]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Deal with BUF_MEM_grow ambiguity
authorRichard Levitte <levitte@openssl.org>
Fri, 30 Aug 2019 14:54:47 +0000 (16:54 +0200)
committerPauli <paul.dale@oracle.com>
Fri, 6 Sep 2019 09:27:57 +0000 (19:27 +1000)
BUF_MEM_grow() returns the passed length, but also zero on error.  If
the passed length was zero, an extra check to see if a returned zero
was an error or not is needed.

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9662)

crypto/evp/pkey_kdf.c

index f4a6093bb1be271a65d7594f839b7c1b93fb082d..f4cf40e6f4bde12094a6656109c14a7924b5e0d3 100644 (file)
@@ -83,9 +83,16 @@ static int collect(BUF_MEM **collector, void *data, size_t datalen)
     }
 
     i = (*collector)->length; /* BUF_MEM_grow() changes it! */
-    if (!BUF_MEM_grow(*collector, i + datalen))
+    /*
+     * The i + datalen check is to distinguish between BUF_MEM_grow()
+     * signaling an error and BUF_MEM_grow() simply returning the (zero)
+     * length.
+     */
+    if (!BUF_MEM_grow(*collector, i + datalen)
+        && i + datalen != 0)
         return 0;
-    memcpy((*collector)->data + i, data, datalen);
+    if (data != NULL)
+        memcpy((*collector)->data + i, data, datalen);
     return 1;
 }