This extracts and updates the fixes reported in issue #1865 back in '09; diff attached.
Administrative: this new bug report implies closing #1865; the
NO_FLOAT_SUPPORT feature mentioned there is removed from the report while
the essential bugfixes which have not been done yet remain in the attached
diff.
edits:
- fmtfp() calls are missing for fp formats, so any fp parts in printf()-ed
text silently /disappears/ erroneously.
- the calculation for the fractional part are wrong (no proper rounding so
fraction will come out wrong), so formats like %.2f will fail, when the
fmtfp() call would've been fixed.
- %p is processed as a signed value which is pure fail for high addresses
(OS/ROM & other pointers on several systems)
- assert --> OPENSSL_assert() so you stay in control like you should in a
dev env.
- bit of in-line documentation + misc.
--- h:\prj\1original\openssl\openssl\crypto\bio\b_print.c 2007-09-15
19:05:11.000000000 +-0200
+++ h:\prj\3actual\openssl\crypto\bio\b_print.c 2009-04-12
07:41:00.000000000 +-0200
@@ -67,13 +67,20 @@
* Stolen from tjh's ssl/ssl_trc.c stuff.
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
+
+#if 0 /* [i_a] -- changed every assert() to OPENSSL_assert() */
#include <assert.h>
+#else
+#include <openssl/e_os2.h>
+#include <openssl/crypto.h>
+#endif
+
#include <limits.h>
#include "cryptlib.h"
#ifndef NO_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <openssl/bn.h> /* To get BN_LLONG properly defined */
@@ -113,14 +120,14 @@
#define LDOUBLE long double
#else
#define LDOUBLE double
#endif
#ifdef HAVE_LONG_LONG
-# if defined(_WIN32) && !defined(__GNUC__)
+# if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__)
# define LLONG __int64
# else
# define LLONG long long
# endif
#else
#define LLONG long
#endif
@@ -144,19 +153,19 @@
#define DP_S_MAX 4
#define DP_S_MOD 5
#define DP_S_CONV 6
#define DP_S_DONE 7
/* format flags - Bits */
-#define DP_F_MINUS (1 << 0)
-#define DP_F_PLUS (1 << 1)
-#define DP_F_SPACE (1 << 2)
-#define DP_F_NUM (1 << 3)
-#define DP_F_ZERO (1 << 4)
-#define DP_F_UP (1 << 5)
-#define DP_F_UNSIGNED (1 << 6)
+#define DP_F_MINUS (1 << 0) /* left-aligned padding */
+#define DP_F_PLUS (1 << 1) /* print an explicit '+' for a value with
positive sign */
+#define DP_F_SPACE (1 << 2) /* print an explicit ' ' for a value with
positive sign */
+#define DP_F_NUM (1 << 3) /* print 0/0x prefix for octal/hex and
decimal point for floating point */
+#define DP_F_ZERO (1 << 4) /* print leading zeroes */
+#define DP_F_UP (1 << 5) /* print HEX in UPPPERcase */
+#define DP_F_UNSIGNED (1 << 6) /* treat value as unsigned */
/* conversion flags */
#define DP_C_SHORT 1
#define DP_C_LONG 2
#define DP_C_LDOUBLE 3
#define DP_C_LLONG 4
@@ -348,21 +356,57 @@
flags |= DP_F_UP;
case 'e':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
+ fmtfp(sbuffer, buffer, &currlen, maxlen,
+ fvalue, min, max, flags); /* [i_a] */
break;
case 'G':
flags |= DP_F_UP;
case 'g':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
+ fmtfp(sbuffer, buffer, &currlen, maxlen,
+ fvalue, min, max, flags); /* [i_a] */
break;
case 'c':
doapr_outch(sbuffer, buffer, &currlen, maxlen,
va_arg(args, int));
break;
case 's':
strvalue = va_arg(args, char *);
@@ -373,15 +417,15 @@
max = *maxlen;
}
fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,
flags, min, max);
break;
case 'p':
- value = (long)va_arg(args, void *);
+ value = (unsigned LLONG)va_arg(args, void *); /* [i_a]
'long' in MSVC is 4 bytes, pointer is 8 on AMD64/AI64 */
fmtint(sbuffer, buffer, &currlen, maxlen,
- value, 16, min, max, flags|DP_F_NUM);
+ value, 16, min, max, flags|DP_F_NUM|DP_F_UNSIGNED);
break;
case 'n': /* XXX */
if (cflags == DP_C_SHORT) {
short int *num;
num = va_arg(args, short int *);
*num = currlen;
@@ -638,13 +683,13 @@
if (max > 9)
max = 9;
/* we "cheat" by converting the fractional part to integer by
multiplying by a factor of 10 */
max10 = roundv(pow_10(max));
- fracpart = roundv(pow_10(max) * (ufvalue - intpart));
+ fracpart = roundv(max10 * (ufvalue - intpart)); /* [i_a] */
if (fracpart >= max10) {
intpart++;
fracpart -= max10;
}
@@ -727,37 +774,37 @@
char **sbuffer,
char **buffer,
size_t *currlen,
size_t *maxlen,
int c)
{
- /* If we haven't at least one buffer, someone has doe a big booboo */
- assert(*sbuffer != NULL || buffer != NULL);
+ /* If we haven't at least one buffer, someone has done a big booboo */
+ OPENSSL_assert(*sbuffer != NULL || buffer != NULL);
if (buffer) {
while (*currlen >= *maxlen) {
if (*buffer == NULL) {
if (*maxlen == 0)
*maxlen = 1024;
*buffer = OPENSSL_malloc(*maxlen);
if (*currlen > 0) {
- assert(*sbuffer != NULL);
+ OPENSSL_assert(*sbuffer != NULL);
memcpy(*buffer, *sbuffer, *currlen);
}
*sbuffer = NULL;
} else {
*maxlen += 1024;
*buffer = OPENSSL_realloc(*buffer, *maxlen);
}
}
/* What to do if *buffer is NULL? */
- assert(*sbuffer != NULL || *buffer != NULL);
+ OPENSSL_assert(*sbuffer != NULL || *buffer != NULL);
}
if (*currlen < *maxlen) {
if (*sbuffer)
(*sbuffer)[(*currlen)++] = (char)c;
else
(*buffer)[(*currlen)++] = (char)c;
}
return;
@@ -762,13 +809,13 @@
return;
}
/***************************************************************************/
-int BIO_printf (BIO *bio, const char *format, ...)
+int BIO_printf(BIO *bio, const char *format, ...)
{
va_list args;
int ret;
va_start(args, format);
--
Met vriendelijke groeten / Best regards,
Ger Hobbelt
--------------------------------------------------
web: http://www.hobbelt.com/
http://www.hebbut.net/
mail: [email protected]
mobile: +31-6-11 120 978
--------------------------------------------------
This extracts and updates the fixes reported in issue #1865 back in '09; diff attached.Administrative: this new bug report implies closing #1865; the NO_FLOAT_SUPPORT feature mentioned there is removed from the report while the essential bugfixes which have not been done yet remain in the attached diff.
edits:
- fmtfp() calls are missing for fp formats, so any fp parts in printf()-ed text silently /disappears/ erroneously.
- the calculation for the fractional part are wrong (no proper rounding so fraction will come out wrong), so formats like %.2f will fail, when the fmtfp() call would've been fixed.
- %p is processed as a signed value which is pure fail for high addresses (OS/ROM & other pointers on several systems)
- assert --> OPENSSL_assert() so you stay in control like you should in a dev env.
- bit of in-line documentation + misc.
--- h:\prj\1original\openssl\openssl\crypto\bio\b_print.c 2007-09-15 19:05:11.000000000 +-0200
+++ h:\prj\3actual\openssl\crypto\bio\b_print.c 2009-04-12 07:41:00.000000000 +-0200
@@ -67,13 +67,20 @@
* Stolen from tjh's ssl/ssl_trc.c stuff.
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
+
+#if 0 /* [i_a] -- changed every assert() to OPENSSL_assert() */
#include <assert.h>
+#else
+#include <openssl/e_os2.h>
+#include <openssl/crypto.h>
+#endif
+
#include <limits.h>
#include "cryptlib.h"
#ifndef NO_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <openssl/bn.h> /* To get BN_LLONG properly defined */
@@ -113,14 +120,14 @@
#define LDOUBLE long double
#else
#define LDOUBLE double
#endif
#ifdef HAVE_LONG_LONG
-# if defined(_WIN32) && !defined(__GNUC__)
+# if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__)
# define LLONG __int64
# else
# define LLONG long long
# endif
#else
#define LLONG long
#endif
@@ -144,19 +153,19 @@
#define DP_S_MAX 4
#define DP_S_MOD 5
#define DP_S_CONV 6
#define DP_S_DONE 7
/* format flags - Bits */
-#define DP_F_MINUS (1 << 0)
-#define DP_F_PLUS (1 << 1)
-#define DP_F_SPACE (1 << 2)
-#define DP_F_NUM (1 << 3)
-#define DP_F_ZERO (1 << 4)
-#define DP_F_UP (1 << 5)
-#define DP_F_UNSIGNED (1 << 6)
+#define DP_F_MINUS (1 << 0) /* left-aligned padding */
+#define DP_F_PLUS (1 << 1) /* print an explicit '+' for a value with positive sign */
+#define DP_F_SPACE (1 << 2) /* print an explicit ' ' for a value with positive sign */
+#define DP_F_NUM (1 << 3) /* print 0/0x prefix for octal/hex and decimal point for floating point */
+#define DP_F_ZERO (1 << 4) /* print leading zeroes */
+#define DP_F_UP (1 << 5) /* print HEX in UPPPERcase */
+#define DP_F_UNSIGNED (1 << 6) /* treat value as unsigned */
/* conversion flags */
#define DP_C_SHORT 1
#define DP_C_LONG 2
#define DP_C_LDOUBLE 3
#define DP_C_LLONG 4
@@ -348,21 +356,57 @@
flags |= DP_F_UP;
case 'e':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
+ fmtfp(sbuffer, buffer, &currlen, maxlen,
+ fvalue, min, max, flags); /* [i_a] */
break;
case 'G':
flags |= DP_F_UP;
case 'g':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
+ fmtfp(sbuffer, buffer, &currlen, maxlen,
+ fvalue, min, max, flags); /* [i_a] */
break;
case 'c':
doapr_outch(sbuffer, buffer, &currlen, maxlen,
va_arg(args, int));
break;
case 's':
strvalue = va_arg(args, char *);
@@ -373,15 +417,15 @@
max = *maxlen;
}
fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,
flags, min, max);
break;
case 'p':
- value = (long)va_arg(args, void *);
+ value = (unsigned LLONG)va_arg(args, void *); /* [i_a] 'long' in MSVC is 4 bytes, pointer is 8 on AMD64/AI64 */
fmtint(sbuffer, buffer, &currlen, maxlen,
- value, 16, min, max, flags|DP_F_NUM);
+ value, 16, min, max, flags|DP_F_NUM|DP_F_UNSIGNED);
break;
case 'n': /* XXX */
if (cflags == DP_C_SHORT) {
short int *num;
num = va_arg(args, short int *);
*num = currlen;
@@ -638,13 +683,13 @@
if (max > 9)
max = 9;
/* we "cheat" by converting the fractional part to integer by
multiplying by a factor of 10 */
max10 = roundv(pow_10(max));
- fracpart = roundv(pow_10(max) * (ufvalue - intpart));
+ fracpart = roundv(max10 * (ufvalue - intpart)); /* [i_a] */
if (fracpart >= max10) {
intpart++;
fracpart -= max10;
}
@@ -727,37 +774,37 @@
char **sbuffer,
char **buffer,
size_t *currlen,
size_t *maxlen,
int c)
{
- /* If we haven't at least one buffer, someone has doe a big booboo */
- assert(*sbuffer != NULL || buffer != NULL);
+ /* If we haven't at least one buffer, someone has done a big booboo */
+ OPENSSL_assert(*sbuffer != NULL || buffer != NULL);
if (buffer) {
while (*currlen >= *maxlen) {
if (*buffer == NULL) {
if (*maxlen == 0)
*maxlen = 1024;
*buffer = OPENSSL_malloc(*maxlen);
if (*currlen > 0) {
- assert(*sbuffer != NULL);
+ OPENSSL_assert(*sbuffer != NULL);
memcpy(*buffer, *sbuffer, *currlen);
}
*sbuffer = NULL;
} else {
*maxlen += 1024;
*buffer = OPENSSL_realloc(*buffer, *maxlen);
}
}
/* What to do if *buffer is NULL? */
- assert(*sbuffer != NULL || *buffer != NULL);
+ OPENSSL_assert(*sbuffer != NULL || *buffer != NULL);
}
if (*currlen < *maxlen) {
if (*sbuffer)
(*sbuffer)[(*currlen)++] = (char)c;
else
(*buffer)[(*currlen)++] = (char)c;
}
return;
@@ -762,13 +809,13 @@
return;
}
/***************************************************************************/
-int BIO_printf (BIO *bio, const char *format, ...)
+int BIO_printf(BIO *bio, const char *format, ...)
{
va_list args;
int ret;
va_start(args, format);
--
Met vriendelijke groeten / Best regards,
Ger Hobbelt
--------------------------------------------------
web: http://www.hobbelt.com/
http://www.hebbut.net/
mail: [email protected]
mobile: +31-6-11 120 978
--------------------------------------------------
--- h:\prj\1original\openssl\openssl\crypto\bio\b_print.c 2007-09-15 19:05:11.000000000 +-0200
+++ h:\prj\3actual\openssl\crypto\bio\b_print.c 2009-04-12 07:41:00.000000000 +-0200
@@ -67,13 +67,20 @@
* Stolen from tjh's ssl/ssl_trc.c stuff.
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
+
+#if 0 /* [i_a] -- changed every assert() to OPENSSL_assert() */
#include <assert.h>
+#else
+#include <openssl/e_os2.h>
+#include <openssl/crypto.h>
+#endif
+
#include <limits.h>
#include "cryptlib.h"
#ifndef NO_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <openssl/bn.h> /* To get BN_LLONG properly defined */
@@ -113,14 +120,14 @@
#define LDOUBLE long double
#else
#define LDOUBLE double
#endif
#ifdef HAVE_LONG_LONG
-# if defined(_WIN32) && !defined(__GNUC__)
+# if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__)
# define LLONG __int64
# else
# define LLONG long long
# endif
#else
#define LLONG long
#endif
@@ -144,19 +153,19 @@
#define DP_S_MAX 4
#define DP_S_MOD 5
#define DP_S_CONV 6
#define DP_S_DONE 7
/* format flags - Bits */
-#define DP_F_MINUS (1 << 0)
-#define DP_F_PLUS (1 << 1)
-#define DP_F_SPACE (1 << 2)
-#define DP_F_NUM (1 << 3)
-#define DP_F_ZERO (1 << 4)
-#define DP_F_UP (1 << 5)
-#define DP_F_UNSIGNED (1 << 6)
+#define DP_F_MINUS (1 << 0) /* left-aligned padding */
+#define DP_F_PLUS (1 << 1) /* print an explicit '+' for a value with positive sign */
+#define DP_F_SPACE (1 << 2) /* print an explicit ' ' for a value with positive sign */
+#define DP_F_NUM (1 << 3) /* print 0/0x prefix for octal/hex and decimal point for floating point */
+#define DP_F_ZERO (1 << 4) /* print leading zeroes */
+#define DP_F_UP (1 << 5) /* print HEX in UPPPERcase */
+#define DP_F_UNSIGNED (1 << 6) /* treat value as unsigned */
/* conversion flags */
#define DP_C_SHORT 1
#define DP_C_LONG 2
#define DP_C_LDOUBLE 3
#define DP_C_LLONG 4
@@ -348,21 +356,57 @@
flags |= DP_F_UP;
case 'e':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
+ fmtfp(sbuffer, buffer, &currlen, maxlen,
+ fvalue, min, max, flags); /* [i_a] */
break;
case 'G':
flags |= DP_F_UP;
case 'g':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
+ fmtfp(sbuffer, buffer, &currlen, maxlen,
+ fvalue, min, max, flags); /* [i_a] */
break;
case 'c':
doapr_outch(sbuffer, buffer, &currlen, maxlen,
va_arg(args, int));
break;
case 's':
strvalue = va_arg(args, char *);
@@ -373,15 +417,15 @@
max = *maxlen;
}
fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,
flags, min, max);
break;
case 'p':
- value = (long)va_arg(args, void *);
+ value = (unsigned LLONG)va_arg(args, void *); /* [i_a] 'long' in MSVC is 4 bytes, pointer is 8 on AMD64/AI64 */
fmtint(sbuffer, buffer, &currlen, maxlen,
- value, 16, min, max, flags|DP_F_NUM);
+ value, 16, min, max, flags|DP_F_NUM|DP_F_UNSIGNED);
break;
case 'n': /* XXX */
if (cflags == DP_C_SHORT) {
short int *num;
num = va_arg(args, short int *);
*num = currlen;
@@ -638,13 +683,13 @@
if (max > 9)
max = 9;
/* we "cheat" by converting the fractional part to integer by
multiplying by a factor of 10 */
max10 = roundv(pow_10(max));
- fracpart = roundv(pow_10(max) * (ufvalue - intpart));
+ fracpart = roundv(max10 * (ufvalue - intpart)); /* [i_a] */
if (fracpart >= max10) {
intpart++;
fracpart -= max10;
}
@@ -727,37 +774,37 @@
char **sbuffer,
char **buffer,
size_t *currlen,
size_t *maxlen,
int c)
{
- /* If we haven't at least one buffer, someone has doe a big booboo */
- assert(*sbuffer != NULL || buffer != NULL);
+ /* If we haven't at least one buffer, someone has done a big booboo */
+ OPENSSL_assert(*sbuffer != NULL || buffer != NULL);
if (buffer) {
while (*currlen >= *maxlen) {
if (*buffer == NULL) {
if (*maxlen == 0)
*maxlen = 1024;
*buffer = OPENSSL_malloc(*maxlen);
if (*currlen > 0) {
- assert(*sbuffer != NULL);
+ OPENSSL_assert(*sbuffer != NULL);
memcpy(*buffer, *sbuffer, *currlen);
}
*sbuffer = NULL;
} else {
*maxlen += 1024;
*buffer = OPENSSL_realloc(*buffer, *maxlen);
}
}
/* What to do if *buffer is NULL? */
- assert(*sbuffer != NULL || *buffer != NULL);
+ OPENSSL_assert(*sbuffer != NULL || *buffer != NULL);
}
if (*currlen < *maxlen) {
if (*sbuffer)
(*sbuffer)[(*currlen)++] = (char)c;
else
(*buffer)[(*currlen)++] = (char)c;
}
return;
@@ -762,13 +809,13 @@
return;
}
/***************************************************************************/
-int BIO_printf (BIO *bio, const char *format, ...)
+int BIO_printf(BIO *bio, const char *format, ...)
{
va_list args;
int ret;
va_start(args, format);
