[openssl-commits] [openssl] master update

Andy Polyakov appro at openssl.org
Thu Mar 30 17:34:49 UTC 2017


The branch master has been updated
       via  5f5840139e3f3ef5681713c6196f93034d9d19f4 (commit)
       via  7d672984f4dc6a87cb0c7d99279c6175fcdc3ad0 (commit)
       via  74d9519a68ee484db584aebc6ab6b2cb4bf98b2a (commit)
      from  12557a3445acc2f53321a3806f0478b998edb9a8 (commit)


- Log -----------------------------------------------------------------
commit 5f5840139e3f3ef5681713c6196f93034d9d19f4
Author: Andy Polyakov <appro at openssl.org>
Date:   Wed Mar 29 23:25:45 2017 +0200

    e_os.h: drop now-redundant PRIu64 [and fix OSSLzu].
    
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/3083)

commit 7d672984f4dc6a87cb0c7d99279c6175fcdc3ad0
Author: Andy Polyakov <appro at openssl.org>
Date:   Wed Mar 29 23:23:56 2017 +0200

    apps/*.c: switch to platform-neutral format modifiers in BIO_print calls.
    
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/3083)

commit 74d9519a68ee484db584aebc6ab6b2cb4bf98b2a
Author: Andy Polyakov <appro at openssl.org>
Date:   Wed Mar 29 23:10:08 2017 +0200

    bio/b_print.c: recognize even 'j' format modifier.
    
    'j' is specified as modifier for "greatest-width integer type", which in
    practice means 64 bits on both 32- and 64-bit platforms. Since we rely
    on __attribute__((__format__(__printf__,...))) to sanitize BIO_print
    format, we can use it to denote [u]int64_t-s in platform-neutral manner.
    
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/3083)

-----------------------------------------------------------------------

Summary of changes:
 CHANGES                 |  6 +++---
 apps/enc.c              |  4 ++--
 apps/s_cb.c             |  4 ++--
 apps/s_client.c         |  4 ++--
 crypto/bio/b_print.c    |  1 +
 e_os.h                  | 41 +++++++++++++++++++++--------------------
 include/openssl/e_os2.h |  1 -
 test/bioprinttest.c     | 34 ++++++++++++++++++++++++++++++----
 8 files changed, 61 insertions(+), 34 deletions(-)

diff --git a/CHANGES b/CHANGES
index d6a09b0..0cce21a 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,9 +4,9 @@
 
  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 the 'z' and 'j' modifiers to BIO_printf() et al formatting string,
+     'z' is to be used for [s]size_t, and 'j' - with [u]int64_t.
+     [Richard Levitte, Andy Polyakov]
 
   *) Add EC_KEY_get0_engine(), which does for EC_KEY what RSA_get0_engine()
      does for RSA, etc.
diff --git a/apps/enc.c b/apps/enc.c
index 30c3c63..a1b2b3c 100644
--- a/apps/enc.c
+++ b/apps/enc.c
@@ -548,8 +548,8 @@ int enc_main(int argc, char **argv)
 
     ret = 0;
     if (verbose) {
-        BIO_printf(bio_err, "bytes read   :%8"PRIu64"\n", BIO_number_read(in));
-        BIO_printf(bio_err, "bytes written:%8"PRIu64"\n", BIO_number_written(out));
+        BIO_printf(bio_err, "bytes read   :%8ju\n", BIO_number_read(in));
+        BIO_printf(bio_err, "bytes written:%8ju\n", BIO_number_written(out));
     }
  end:
     ERR_print_errors(bio_err);
diff --git a/apps/s_cb.c b/apps/s_cb.c
index 4400580..f395a2a 100644
--- a/apps/s_cb.c
+++ b/apps/s_cb.c
@@ -1042,8 +1042,8 @@ static char *hexencode(const unsigned char *data, size_t len)
     int ilen = (int) outlen;
 
     if (outlen < len || ilen < 0 || outlen != (size_t)ilen) {
-        BIO_printf(bio_err, "%s: %" PRIu64 "-byte buffer too large to hexencode\n",
-                   opt_getprog(), (uint64_t)len);
+        BIO_printf(bio_err, "%s: %zu-byte buffer too large to hexencode\n",
+                   opt_getprog(), len);
         exit(1);
     }
     cp = out = app_malloc(ilen, "TLSA hex data buffer");
diff --git a/apps/s_client.c b/apps/s_client.c
index fc18da2..cab7e25 100644
--- a/apps/s_client.c
+++ b/apps/s_client.c
@@ -2901,8 +2901,8 @@ static void print_stuff(BIO *bio, SSL *s, int full)
 #endif
 
         BIO_printf(bio,
-                   "---\nSSL handshake has read %" PRIu64
-                   " bytes and written %" PRIu64 " bytes\n",
+                   "---\nSSL handshake has read %ju bytes "
+                   "and written %ju bytes\n",
                    BIO_number_read(SSL_get_rbio(s)),
                    BIO_number_written(SSL_get_wbio(s)));
     }
diff --git a/crypto/bio/b_print.c b/crypto/bio/b_print.c
index 883af19..79ae4a9 100644
--- a/crypto/bio/b_print.c
+++ b/crypto/bio/b_print.c
@@ -208,6 +208,7 @@ _dopr(char **sbuffer,
                 ch = *format++;
                 break;
             case 'q':
+            case 'j':
                 cflags = DP_C_LLONG;
                 ch = *format++;
                 break;
diff --git a/e_os.h b/e_os.h
index 241e0ba..914a2bf 100644
--- a/e_os.h
+++ b/e_os.h
@@ -30,29 +30,30 @@ extern "C" {
 # endif
 
 /*
- * We need a format operator for some client tools for uint64_t.  If inttypes.h
- * isn't available or did not define it, just go with hard-coded.
+ * Format specifier for printing size_t. Original conundrum was to
+ * get it working with -Wformat [-Werror], which can be considered
+ * overzelaous, especially in multi-platform context, but it's
+ * conscious choice...
  */
-# if defined(OPENSSL_SYS_UEFI)
-#  define PRIu64 "Lu"
-# endif
-# ifndef PRIu64
-#  ifdef SIXTY_FOUR_BIT_LONG
-#   define PRIu64 "lu"
-#  else
-#   define PRIu64 "llu"
-#  endif
-# endif
-
-/* Format specifier for printing size_t */
-# if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
+# if defined(_WIN64)
+#  define OSSLzu  "I64u"    /* One would expect _WIN{64|32} cases after
+                             * __STDC_VERSION__, but there are corner
+                             * cases of MinGW compilers that link with
+                             * non-compliant MSVCRT.DLL... */
+# elif defined(_WIN32)
+#  define OSSLzu  "u"
+# elif defined(__VMS)
+#  define OSSLzu  "u"       /* VMS suffers from similar problem as MinGW,
+                             * i.e. C RTL falling behind compiler. Recall
+                             * that sizeof(size_t)==4 even in LP64 case. */
+# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
 #  define OSSLzu  "zu"
+# elif defined(__SIZEOF_SIZE_T__) && __SIZEOF_SIZE_T__==4
+#  define OSSLzu  "u"       /* 'lu' should have worked, but when generating
+                             * 32-bit code gcc still complains :-( */
 # else
-#  ifdef THIRTY_TWO_BIT
-#   define OSSLzu "u"
-#  else
-#   define OSSLzu PRIu64
-#  endif
+#  define OSSLzu  "lu"      /* To see that is works recall what does L
+                             * stand for in ILP32 and LP64 */
 # endif
 
 # if !defined(NDEBUG) && !defined(OPENSSL_NO_STDIO)
diff --git a/include/openssl/e_os2.h b/include/openssl/e_os2.h
index c1a9ad7..717cadf 100644
--- a/include/openssl/e_os2.h
+++ b/include/openssl/e_os2.h
@@ -236,7 +236,6 @@ typedef INT32 int32_t;
 typedef UINT32 uint32_t;
 typedef INT64 int64_t;
 typedef UINT64 uint64_t;
-#  define PRIu64 "%Lu"
 # elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
      defined(__osf__) || defined(__sgi) || defined(__hpux) || \
      defined(OPENSSL_SYS_VMS) || defined (__OpenBSD__)
diff --git a/test/bioprinttest.c b/test/bioprinttest.c
index c3ab6a1..4eeb4c6 100644
--- a/test/bioprinttest.c
+++ b/test/bioprinttest.c
@@ -173,6 +173,34 @@ static void dozutest(int test, const struct z_data_st *data, int *fail)
     }
 }
 
+struct j_data_st {
+    uint64_t value;
+    const char *format;
+    const char *expected;
+};
+static struct j_data_st j_data[] = {
+    { 0xffffffffffffffffU, "%ju", "18446744073709551615" },
+    { 0xffffffffffffffffU, "%jx", "ffffffffffffffff" },
+    { 0x8000000000000000U, "%ju", "9223372036854775808" },
+    /*
+     * These tests imply two's-complement, but it's the only binary
+     * representation we support, see test/sanitytest.c...
+     */
+    { 0x8000000000000000U, "%ji", "-9223372036854775808" },
+};
+
+static void dojtest(int test, const struct j_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;
@@ -246,11 +274,9 @@ int main(int argc, char **argv)
         dozutest(test++, &zu_data[i], &fail);
     }
 
-#if 0
-    for (i = 0; i < nelem(zi_data); i++) {
-        dozitest(test++, &zu_data[i], &fail);
+    for (i = 0; i < nelem(j_data); i++) {
+        dojtest(test++, &j_data[i], &fail);
     }
-#endif
 
 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
     if (CRYPTO_mem_leaks_fp(stderr) <= 0)


More information about the openssl-commits mailing list