[openssl] master update

Dr. Paul Dale pauli at openssl.org
Tue Jun 22 09:50:55 UTC 2021


The branch master has been updated
       via  e493d6e0ca4157741d2e4cfcb91fd367851f5771 (commit)
       via  2086818a3142510031f58cfac85747d0393637ed (commit)
       via  08ee6addf7343e7523db47dcc7e84e1670d52e15 (commit)
      from  b1fa45b01ba55a95bea1a4f05444f40be1b126f5 (commit)


- Log -----------------------------------------------------------------
commit e493d6e0ca4157741d2e4cfcb91fd367851f5771
Author: Richard Levitte <levitte at openssl.org>
Date:   Mon Jun 21 09:25:16 2021 +0200

    APPS & TEST: Use ossl_[u]intmax_t rather than [u]intmax_t
    
    Reviewed-by: Paul Dale <pauli at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/15825)

commit 2086818a3142510031f58cfac85747d0393637ed
Author: Richard Levitte <levitte at openssl.org>
Date:   Fri Jun 18 10:54:01 2021 +0200

    APPS: Make fallback opt_[u]intmax() implementations based on long
    
    Also ensure that opt_intmax() and opt_uintmax() does the right thing
    if sizeof([u]intmax_t) is smaller than sizeof(ossl_[u]intmax_t).
    
    Reviewed-by: Paul Dale <pauli at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/15825)

commit 08ee6addf7343e7523db47dcc7e84e1670d52e15
Author: Richard Levitte <levitte at openssl.org>
Date:   Fri Jun 18 10:32:32 2021 +0200

    Fix definition of ossl_intmax_t and ossl_uintmax_t
    
    These definitions were located away from our definitions of other
    sized int and uint types.  Also, the fallback typedef wasn't quite
    correct, and this changes it to be aliases for int64_t and uint64_t,
    since those are the largest integers we commonly handle.
    
    We also make sure to define corresponding numbers: OSSL_INTMAX_MIN,
    OSSL_INTMAX_MAX and OSSL_UINTMAX_MAX
    
    Reviewed-by: Paul Dale <pauli at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/15825)

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

Summary of changes:
 apps/include/opt.h         | 13 ++-----------
 apps/lib/opt.c             | 45 ++++++++++++++++++++++++++++++++++++++++-----
 apps/x509.c                |  4 ++--
 include/internal/numbers.h |  6 ++++++
 include/openssl/e_os2.h    |  9 +++++++++
 include/openssl/types.h    | 15 ---------------
 test/ecstresstest.c        |  7 ++++---
 7 files changed, 63 insertions(+), 36 deletions(-)

diff --git a/apps/include/opt.h b/apps/include/opt.h
index 4a292213fd..ce0e35cd72 100644
--- a/apps/include/opt.h
+++ b/apps/include/opt.h
@@ -375,17 +375,8 @@ int opt_int(const char *arg, int *result);
 int opt_int_arg(void);
 int opt_long(const char *arg, long *result);
 int opt_ulong(const char *arg, unsigned long *result);
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && \
-    defined(INTMAX_MAX) && defined(UINTMAX_MAX) && \
-    !defined(OPENSSL_NO_INTTYPES_H)
-int opt_intmax(const char *arg, intmax_t *result);
-int opt_uintmax(const char *arg, uintmax_t *result);
-#else
-# define opt_intmax opt_long
-# define opt_uintmax opt_ulong
-# define intmax_t long
-# define uintmax_t unsigned long
-#endif
+int opt_intmax(const char *arg, ossl_intmax_t *result);
+int opt_uintmax(const char *arg, ossl_uintmax_t *result);
 
 int opt_isdir(const char *name);
 int opt_format(const char *s, unsigned long flags, int *result);
diff --git a/apps/lib/opt.c b/apps/lib/opt.c
index c88c99b5e6..adb0417bd8 100644
--- a/apps/lib/opt.c
+++ b/apps/lib/opt.c
@@ -14,6 +14,7 @@
 #include "fmt.h"
 #include "app_libctx.h"
 #include "internal/nelem.h"
+#include "internal/numbers.h"
 #include <string.h>
 #if !defined(OPENSSL_SYS_MSDOS)
 # include <unistd.h>
@@ -555,7 +556,7 @@ int opt_long(const char *value, long *result)
     !defined(OPENSSL_NO_INTTYPES_H)
 
 /* Parse an intmax_t, put it into *result; return 0 on failure, else 1. */
-int opt_intmax(const char *value, intmax_t *result)
+int opt_intmax(const char *value, ossl_intmax_t *result)
 {
     int oerrno = errno;
     intmax_t m;
@@ -565,19 +566,26 @@ int opt_intmax(const char *value, intmax_t *result)
     m = strtoimax(value, &endp, 0);
     if (*endp
             || endp == value
-            || ((m == INTMAX_MAX || m == INTMAX_MIN) && errno == ERANGE)
+            || ((m == INTMAX_MAX || m == INTMAX_MIN)
+                && errno == ERANGE)
             || (m == 0 && errno != 0)) {
         opt_number_error(value);
         errno = oerrno;
         return 0;
     }
-    *result = m;
+    /* Ensure that the value in |m| is never too big for |*result| */
+    if (sizeof(m) > sizeof(*result)
+        && (m < OSSL_INTMAX_MIN || m > OSSL_INTMAX_MAX)) {
+        opt_number_error(value);
+        return 0;
+    }
+    *result = (ossl_intmax_t)m;
     errno = oerrno;
     return 1;
 }
 
 /* Parse a uintmax_t, put it into *result; return 0 on failure, else 1. */
-int opt_uintmax(const char *value, uintmax_t *result)
+int opt_uintmax(const char *value, ossl_uintmax_t *result)
 {
     int oerrno = errno;
     uintmax_t m;
@@ -593,10 +601,37 @@ int opt_uintmax(const char *value, uintmax_t *result)
         errno = oerrno;
         return 0;
     }
-    *result = m;
+    /* Ensure that the value in |m| is never too big for |*result| */
+    if (sizeof(m) > sizeof(*result)
+        && m > OSSL_UINTMAX_MAX) {
+        opt_number_error(value);
+        return 0;
+    }
+    *result = (ossl_intmax_t)m;
     errno = oerrno;
     return 1;
 }
+#else
+/* Fallback implementations based on long */
+int opt_intmax(const char *value, ossl_intmax_t *result)
+{
+    long m;
+    int ret;
+
+    if ((ret = opt_long(value, &m)))
+        *result = m;
+    return ret;
+}
+
+int opt_uintmax(const char *value, ossl_uintmax_t *result)
+{
+    unsigned long m;
+    int ret;
+
+    if ((ret = opt_ulong(value, &m)))
+        *result = m;
+    return ret;
+}
 #endif
 
 /*
diff --git a/apps/x509.c b/apps/x509.c
index 25c75e8574..558351ba30 100644
--- a/apps/x509.c
+++ b/apps/x509.c
@@ -553,11 +553,11 @@ int x509_main(int argc, char **argv)
         case OPT_CHECKEND:
             checkend = 1;
             {
-                intmax_t temp = 0;
+                ossl_intmax_t temp = 0;
                 if (!opt_intmax(opt_arg(), &temp))
                     goto opthelp;
                 checkoffset = (time_t)temp;
-                if ((intmax_t)checkoffset != temp) {
+                if ((ossl_intmax_t)checkoffset != temp) {
                     BIO_printf(bio_err, "%s: Checkend time out of range %s\n",
                                prog, opt_arg());
                     goto opthelp;
diff --git a/include/internal/numbers.h b/include/internal/numbers.h
index ac801364d9..4f4d3306d5 100644
--- a/include/internal/numbers.h
+++ b/include/internal/numbers.h
@@ -75,5 +75,11 @@ typedef __uint128_t uint128_t;
 #  define SIZE_MAX __MAXUINT__(size_t)
 # endif
 
+# ifndef OSSL_INTMAX_MAX
+#  define OSSL_INTMAX_MIN __MININT__(ossl_intmax_t)
+#  define OSSL_INTMAX_MAX __MAXINT__(ossl_intmax_t)
+#  define OSSL_UINTMAX_MAX __MAXUINT__(ossl_uintmax_t)
+# endif
+
 #endif
 
diff --git a/include/openssl/e_os2.h b/include/openssl/e_os2.h
index 49e6dad73c..6728909271 100644
--- a/include/openssl/e_os2.h
+++ b/include/openssl/e_os2.h
@@ -252,6 +252,15 @@ typedef unsigned __int64 uint64_t;
 #  include <stdint.h>
 #  undef OPENSSL_NO_STDINT_H
 # endif
+# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && \
+    defined(INTMAX_MAX) && defined(UINTMAX_MAX)
+typedef intmax_t ossl_intmax_t;
+typedef uintmax_t ossl_uintmax_t;
+# else
+/* Fall back to the largest we know we require and can handle */
+typedef int64_t ossl_intmax_t;
+typedef uint64_t ossl_uintmax_t;
+# endif
 
 /* ossl_inline: portable inline definition usable in public headers */
 # if !defined(inline) && !defined(__cplusplus)
diff --git a/include/openssl/types.h b/include/openssl/types.h
index bf5846db05..de9f166524 100644
--- a/include/openssl/types.h
+++ b/include/openssl/types.h
@@ -229,21 +229,6 @@ typedef struct ossl_decoder_ctx_st OSSL_DECODER_CTX;
 
 typedef struct ossl_self_test_st OSSL_SELF_TEST;
 
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && \
-    defined(INTMAX_MAX) && defined(UINTMAX_MAX)
-typedef intmax_t ossl_intmax_t;
-typedef uintmax_t ossl_uintmax_t;
-#else
-/*
- * Not long long, because the C-library can only be expected to provide
- * strtoll(), strtoull() at the same time as intmax_t and strtoimax(),
- * strtoumax().  Since we use these for parsing arguments, we need the
- * conversion functions, not just the sizes.
- */
-typedef long ossl_intmax_t;
-typedef unsigned long ossl_uintmax_t;
-#endif
-
 #ifdef  __cplusplus
 }
 #endif
diff --git a/test/ecstresstest.c b/test/ecstresstest.c
index 1ffb7e522e..22d46c50da 100644
--- a/test/ecstresstest.c
+++ b/test/ecstresstest.c
@@ -18,7 +18,7 @@
 
 #define NUM_REPEATS "1000000"
 
-static intmax_t num_repeats;
+static ossl_intmax_t num_repeats;
 static int print_mode = 0;
 
 #ifndef OPENSSL_NO_EC
@@ -39,10 +39,11 @@ static const char *kP256DefaultResult =
  * point multiplication.
  * Returns the X-coordinate of the end result or NULL on error.
  */
-static BIGNUM *walk_curve(const EC_GROUP *group, EC_POINT *point, intmax_t num)
+static BIGNUM *walk_curve(const EC_GROUP *group, EC_POINT *point,
+                          ossl_intmax_t num)
 {
     BIGNUM *scalar = NULL;
-    intmax_t i;
+    ossl_intmax_t i;
 
     if (!TEST_ptr(scalar = BN_new())
             || !TEST_true(EC_POINT_get_affine_coordinates(group, point, scalar,


More information about the openssl-commits mailing list