[openssl-commits] [openssl] master update
Richard Levitte
levitte at openssl.org
Wed Mar 29 14:16:29 UTC 2017
The branch master has been updated
via 6e6aa5a9db9c5dce87aeb832f1a3bd105ec40120 (commit)
via 1bcf7d45c63321f4efd354782be8924d688b0757 (commit)
via 1e53a9fd1ad1260274065c12d0e9efbabb7d94e1 (commit)
from 6edc71456463f66008b9cf40dadf00aba037f8da (commit)
- Log -----------------------------------------------------------------
commit 6e6aa5a9db9c5dce87aeb832f1a3bd105ec40120
Author: Richard Levitte <levitte at openssl.org>
Date: Tue Mar 28 19:42:53 2017 +0200
Add a simple test for the z modifier
Reviewed-by: Andy Polyakov <appro at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3064)
commit 1bcf7d45c63321f4efd354782be8924d688b0757
Author: Richard Levitte <levitte at openssl.org>
Date: Tue Mar 28 17:04:43 2017 +0200
Use the z modifier instead of OSSLzu with BIO_printf
Reviewed-by: Andy Polyakov <appro at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3064)
commit 1e53a9fd1ad1260274065c12d0e9efbabb7d94e1
Author: Richard Levitte <levitte at openssl.org>
Date: Tue Mar 28 16:57:41 2017 +0200
Add z modifier parsing to the BIO_printf et all format string
Reviewed-by: Andy Polyakov <appro at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3064)
-----------------------------------------------------------------------
Summary of changes:
CHANGES | 4 ++++
crypto/bio/b_print.c | 13 +++++++++++-
include/openssl/bio.h | 14 +++++++++----
test/bioprinttest.c | 47 +++++++++++++++++++++++++++++++++++++++++++-
test/siphash_internal_test.c | 2 +-
5 files changed, 73 insertions(+), 7 deletions(-)
diff --git a/CHANGES b/CHANGES
index 2cdd03a..d6a09b0 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,10 @@
Changes between 1.1.0e and 1.1.1 [xx XXX xxxx]
+ *) Add the z modifier parsing to BIO_printf() et al formatting string,
+ to be used for size_t and ssize_t (ossl_ssize_t).
+ [Richard Levitte]
+
*) Add EC_KEY_get0_engine(), which does for EC_KEY what RSA_get0_engine()
does for RSA, etc.
[Richard Levitte]
diff --git a/crypto/bio/b_print.c b/crypto/bio/b_print.c
index e91ab6d..86aec79 100644
--- a/crypto/bio/b_print.c
+++ b/crypto/bio/b_print.c
@@ -89,6 +89,7 @@ static int _dopr(char **sbuffer, char **buffer,
#define DP_C_LONG 2
#define DP_C_LDOUBLE 3
#define DP_C_LLONG 4
+#define DP_C_SIZE 5
/* Floating point formats */
#define F_FORMAT 0
@@ -214,6 +215,10 @@ _dopr(char **sbuffer,
cflags = DP_C_LDOUBLE;
ch = *format++;
break;
+ case 'z':
+ cflags = DP_C_SIZE;
+ ch = *format++;
+ break;
default:
break;
}
@@ -233,6 +238,9 @@ _dopr(char **sbuffer,
case DP_C_LLONG:
value = va_arg(args, LLONG);
break;
+ case DP_C_SIZE:
+ value = va_arg(args, ossl_ssize_t);
+ break;
default:
value = va_arg(args, int);
break;
@@ -253,11 +261,14 @@ _dopr(char **sbuffer,
value = (unsigned short int)va_arg(args, unsigned int);
break;
case DP_C_LONG:
- value = (LLONG) va_arg(args, unsigned long int);
+ value = (LLONG)va_arg(args, unsigned long int);
break;
case DP_C_LLONG:
value = va_arg(args, unsigned LLONG);
break;
+ case DP_C_SIZE:
+ value = (ossl_ssize_t)va_arg(args, size_t);
+ break;
default:
value = (LLONG) va_arg(args, unsigned int);
break;
diff --git a/include/openssl/bio.h b/include/openssl/bio.h
index 0cf095e..6585ec0 100644
--- a/include/openssl/bio.h
+++ b/include/openssl/bio.h
@@ -724,10 +724,16 @@ void BIO_copy_next_retry(BIO *b);
* long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);
*/
-# ifdef __GNUC__
-# define __bio_h__attr__ __attribute__
-# else
-# define __bio_h__attr__(x)
+# define __bio_h__attr__(x)
+# if defined(__GNUC__) && defined(__STDC_VERSION__)
+ /*
+ * Because we support the 'z' modifier, which made its appearance in C99,
+ * we can't use __attribute__ with pre C99 dialects.
+ */
+# if __STDC_VERSION__ >= 199901L
+# undef __bio_h__attr__
+# define __bio_h__attr__ __attribute__
+# endif
# endif
int BIO_printf(BIO *bio, const char *format, ...)
__bio_h__attr__((__format__(__printf__, 2, 3)));
diff --git a/test/bioprinttest.c b/test/bioprinttest.c
index b2d2622..c3ab6a1 100644
--- a/test/bioprinttest.c
+++ b/test/bioprinttest.c
@@ -10,6 +10,9 @@
#include <stdio.h>
#include <string.h>
#include <openssl/bio.h>
+#include "internal/numbers.h"
+
+#define nelem(x) (sizeof(x)/sizeof((x)[0]))
static int justprint = 0;
@@ -138,10 +141,42 @@ static void dofptest(int test, double val, char *width, int prec, int *fail)
}
}
+struct z_data_st {
+ size_t value;
+ const char *format;
+ const char *expected;
+};
+static struct z_data_st zu_data[] = {
+ { SIZE_MAX, "%zu", (sizeof(size_t) == 4 ? "4294967295"
+ : sizeof(size_t) == 8 ? "18446744073709551615"
+ : "") },
+ /*
+ * in 2-complement, the unsigned number divided by two plus one becomes the
+ * smallest possible negative signed number of the corresponding type
+ */
+ { SIZE_MAX / 2 + 1, "%zi", (sizeof(size_t) == 4 ? "-2147483648"
+ : sizeof(size_t) == 8 ? "-9223372036854775808"
+ : "") },
+ { 0, "%zu", "0" },
+ { 0, "%zi", "0" },
+};
+
+static void dozutest(int test, const struct z_data_st *data, int *fail)
+{
+ char bio_buf[80];
+
+ BIO_snprintf(bio_buf, sizeof(bio_buf) - 1, data->format, data->value);
+ if (strcmp(bio_buf, data->expected) != 0) {
+ printf("Test %d failed. Expected \"%s\". Got \"%s\". "
+ "Format \"%s\"\n", test, data->expected, bio_buf, data->format);
+ *fail = 1;
+ }
+}
+
int main(int argc, char **argv)
{
int test = 0;
- int i;
+ size_t i;
int fail = 0;
int prec = -1;
char *width = "";
@@ -207,6 +242,16 @@ int main(int argc, char **argv)
fail = 1;
}
+ for (i = 0; i < nelem(zu_data); i++) {
+ dozutest(test++, &zu_data[i], &fail);
+ }
+
+#if 0
+ for (i = 0; i < nelem(zi_data); i++) {
+ dozitest(test++, &zu_data[i], &fail);
+ }
+#endif
+
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (CRYPTO_mem_leaks_fp(stderr) <= 0)
return 1;
diff --git a/test/siphash_internal_test.c b/test/siphash_internal_test.c
index 46b4660..eee4736 100644
--- a/test/siphash_internal_test.c
+++ b/test/siphash_internal_test.c
@@ -321,7 +321,7 @@ static int test_siphash(int idx)
}
if (memcmp(out, expected, expectedlen) != 0) {
- BIO_printf(b_stderr, "SipHash test #%d/%" OSSLzu "+%" OSSLzu " failed.\n",
+ BIO_printf(b_stderr, "SipHash test #%d/%zu+%zu failed.\n",
idx, half, inlen-half);
hex_out(b_stderr, "got: ", 16, out, expectedlen);
hex_out(b_stderr, "expected: ", 16, expected, expectedlen);
More information about the openssl-commits
mailing list