[openssl-commits] [openssl] master update

paul.dale at oracle.com paul.dale at oracle.com
Thu Sep 14 00:27:35 UTC 2017


The branch master has been updated
       via  76b2ae832679d25e6952934481ac38e0e76e2271 (commit)
       via  f4eb24839228675386d0cbfd3e5c2291763a0be4 (commit)
       via  582e2ed2718bd367e747cb9077d2044cf51cc9a4 (commit)
       via  4cacc9d510c20368d13dcaf2c95c25d6d1ceef6c (commit)
      from  eff1752b66cb7bf6ca8af816eb10ead26910d025 (commit)


- Log -----------------------------------------------------------------
commit 76b2ae832679d25e6952934481ac38e0e76e2271
Author: Pauli <paul.dale at oracle.com>
Date:   Thu Sep 14 10:05:22 2017 +1000

    Ensure that the requested memory size cannot exceed the limit imposed by a
    size_t variable.
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/4357)

commit f4eb24839228675386d0cbfd3e5c2291763a0be4
Author: Pauli <paul.dale at oracle.com>
Date:   Tue Sep 12 09:18:17 2017 +1000

    Manually revert "Ensure allocation size fits into size_t"
    
    This reverts commit cc9c56894606fdf324933cd8090d9a54d967bf5b for the file
    pbe_scrypt.c instead of scrypt.c
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/4357)

commit 582e2ed2718bd367e747cb9077d2044cf51cc9a4
Author: Pauli <paul.dale at oracle.com>
Date:   Tue Sep 12 09:13:12 2017 +1000

    Revert "Reuse strndup(), simplify code"
    
    This reverts commit 1caaea133873d549fa52fbf265298d2d35442477.
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/4357)

commit 4cacc9d510c20368d13dcaf2c95c25d6d1ceef6c
Author: Pauli <paul.dale at oracle.com>
Date:   Tue Sep 12 09:13:00 2017 +1000

    Revert "GH614: Use memcpy()/strdup() when possible"
    
    This reverts commit a89c9a0d855bce735116acfe147b24e386f566ba.
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/4357)

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

Summary of changes:
 crypto/dso/dso_dl.c     |  6 ++++--
 crypto/dso/dso_dlfcn.c  |  6 ++++--
 crypto/evp/pbe_scrypt.c | 17 ++++++-----------
 crypto/o_str.c          |  6 ++----
 crypto/x509/by_dir.c    | 17 +++++++++--------
 ssl/ssl_lib.c           |  2 +-
 6 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/crypto/dso/dso_dl.c b/crypto/dso/dso_dl.c
index d80bf56..af968e3 100644
--- a/crypto/dso/dso_dl.c
+++ b/crypto/dso/dso_dl.c
@@ -156,21 +156,23 @@ static char *dl_merger(DSO *dso, const char *filespec1, const char *filespec2)
      * if the second file specification is missing.
      */
     if (!filespec2 || filespec1[0] == '/') {
-        merged = OPENSSL_strdup(filespec1);
+        merged = OPENSSL_malloc(strlen(filespec1) + 1);
         if (merged == NULL) {
             DSOerr(DSO_F_DL_MERGER, ERR_R_MALLOC_FAILURE);
             return (NULL);
         }
+        strcpy(merged, filespec1);
     }
     /*
      * If the first file specification is missing, the second one rules.
      */
     else if (!filespec1) {
-        merged = OPENSSL_strdup(filespec2);
+        merged = OPENSSL_malloc(strlen(filespec2) + 1);
         if (merged == NULL) {
             DSOerr(DSO_F_DL_MERGER, ERR_R_MALLOC_FAILURE);
             return (NULL);
         }
+        strcpy(merged, filespec2);
     } else
         /*
          * This part isn't as trivial as it looks.  It assumes that the
diff --git a/crypto/dso/dso_dlfcn.c b/crypto/dso/dso_dlfcn.c
index a4b0cdd..e2aa76e 100644
--- a/crypto/dso/dso_dlfcn.c
+++ b/crypto/dso/dso_dlfcn.c
@@ -196,21 +196,23 @@ static char *dlfcn_merger(DSO *dso, const char *filespec1,
      * if the second file specification is missing.
      */
     if (!filespec2 || (filespec1 != NULL && filespec1[0] == '/')) {
-        merged = OPENSSL_strdup(filespec1);
+        merged = OPENSSL_malloc(strlen(filespec1) + 1);
         if (merged == NULL) {
             DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE);
             return (NULL);
         }
+        strcpy(merged, filespec1);
     }
     /*
      * If the first file specification is missing, the second one rules.
      */
     else if (!filespec1) {
-        merged = OPENSSL_strdup(filespec2);
+        merged = OPENSSL_malloc(strlen(filespec2) + 1);
         if (merged == NULL) {
             DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE);
             return (NULL);
         }
+        strcpy(merged, filespec2);
     } else {
         /*
          * This part isn't as trivial as it looks.  It assumes that the
diff --git a/crypto/evp/pbe_scrypt.c b/crypto/evp/pbe_scrypt.c
index a52cd75..80a1acd 100644
--- a/crypto/evp/pbe_scrypt.c
+++ b/crypto/evp/pbe_scrypt.c
@@ -164,7 +164,6 @@ int EVP_PBE_scrypt(const char *pass, size_t passlen,
     unsigned char *B;
     uint32_t *X, *V, *T;
     uint64_t i, Blen, Vlen;
-    size_t allocsize;
 
     /* Sanity check parameters */
     /* initial check, r,p must be non zero, N >= 2 and a power of 2 */
@@ -194,8 +193,7 @@ int EVP_PBE_scrypt(const char *pass, size_t passlen,
     Blen = p * 128 * r;
 
     /*
-     * Check 32 * r * (N + 2) * sizeof(uint32_t) fits in
-     * uint64_t and also size_t (their sizes are unrelated).
+     * Check 32 * r * (N + 2) * sizeof(uint32_t) fits in uint64_t
      * This is combined size V, X and T (section 4)
      */
     i = UINT64_MAX / (32 * sizeof(uint32_t));
@@ -206,16 +204,13 @@ int EVP_PBE_scrypt(const char *pass, size_t passlen,
     /* check total allocated size fits in uint64_t */
     if (Blen > UINT64_MAX - Vlen)
         return 0;
-    /* check total allocated size fits in size_t */
-    if (Blen > SIZE_MAX - Vlen)
-        return 0;
-
-    allocsize = (size_t)(Blen + Vlen);
 
     if (maxmem == 0)
         maxmem = SCRYPT_MAX_MEM;
+    if (maxmem > SIZE_MAX)
+        maxmem = SIZE_MAX;
 
-    if (allocsize > maxmem) {
+    if (Blen + Vlen > maxmem) {
         EVPerr(EVP_F_EVP_PBE_SCRYPT, EVP_R_MEMORY_LIMIT_EXCEEDED);
         return 0;
     }
@@ -224,7 +219,7 @@ int EVP_PBE_scrypt(const char *pass, size_t passlen,
     if (key == NULL)
         return 1;
 
-    B = OPENSSL_malloc(allocsize);
+    B = OPENSSL_malloc(Blen + Vlen);
     if (B == NULL)
         return 0;
     X = (uint32_t *)(B + Blen);
@@ -242,7 +237,7 @@ int EVP_PBE_scrypt(const char *pass, size_t passlen,
         goto err;
     rv = 1;
  err:
-    OPENSSL_clear_free(B, allocsize);
+    OPENSSL_clear_free(B, Blen + Vlen);
     return rv;
 }
 #endif
diff --git a/crypto/o_str.c b/crypto/o_str.c
index cf098fc..a835769 100644
--- a/crypto/o_str.c
+++ b/crypto/o_str.c
@@ -27,14 +27,12 @@ int OPENSSL_memcmp(const void *v1, const void *v2, size_t n)
 char *CRYPTO_strdup(const char *str, const char* file, int line)
 {
     char *ret;
-    size_t size;
 
     if (str == NULL)
         return NULL;
-    size = strlen(str) + 1;
-    ret = CRYPTO_malloc(size, file, line);
+    ret = CRYPTO_malloc(strlen(str) + 1, file, line);
     if (ret != NULL)
-        memcpy(ret, str, size);
+        strcpy(ret, str);
     return ret;
 }
 
diff --git a/crypto/x509/by_dir.c b/crypto/x509/by_dir.c
index 8476f00..e1a09cb 100644
--- a/crypto/x509/by_dir.c
+++ b/crypto/x509/by_dir.c
@@ -150,7 +150,8 @@ static void free_dir(X509_LOOKUP *lu)
 
 static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
 {
-    const char *s, *p;
+    int j, len;
+    const char *s, *ss, *p;
 
     if (dir == NULL || !*dir) {
         X509err(X509_F_ADD_CERT_DIR, X509_R_INVALID_DIRECTORY);
@@ -162,17 +163,15 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
     do {
         if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0')) {
             BY_DIR_ENTRY *ent;
-            int j;
-            size_t len;
-            const char *ss = s;
+            ss = s;
             s = p + 1;
-            len = p - ss;
+            len = (int)(p - ss);
             if (len == 0)
                 continue;
             for (j = 0; j < sk_BY_DIR_ENTRY_num(ctx->dirs); j++) {
                 ent = sk_BY_DIR_ENTRY_value(ctx->dirs, j);
-                if (strlen(ent->dir) == len &&
-                    strncmp(ent->dir, ss, len) == 0)
+                if (strlen(ent->dir) == (size_t)len &&
+                    strncmp(ent->dir, ss, (unsigned int)len) == 0)
                     break;
             }
             if (j < sk_BY_DIR_ENTRY_num(ctx->dirs))
@@ -189,11 +188,13 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
                 return 0;
             ent->dir_type = type;
             ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp);
-            ent->dir = OPENSSL_strndup(ss, len);
+            ent->dir = OPENSSL_malloc((unsigned int)len + 1);
             if (ent->dir == NULL || ent->hashes == NULL) {
                 by_dir_entry_free(ent);
                 return 0;
             }
+            strncpy(ent->dir, ss, (unsigned int)len);
+            ent->dir[len] = '\0';
             if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) {
                 by_dir_entry_free(ent);
                 return 0;
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
index a909a57..a3c5151 100644
--- a/ssl/ssl_lib.c
+++ b/ssl/ssl_lib.c
@@ -2471,7 +2471,7 @@ char *SSL_get_shared_ciphers(const SSL *s, char *buf, int len)
             *p = '\0';
             return buf;
         }
-        memcpy(p, c->name, n + 1);
+        strcpy(p, c->name);
         p += n;
         *(p++) = ':';
         len -= n + 1;


More information about the openssl-commits mailing list