Fix the error handling in CRYPTO_dup_ex_data.
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Mon, 20 Mar 2017 19:50:23 +0000 (20:50 +0100)
committerRichard Levitte <levitte@openssl.org>
Wed, 29 Mar 2017 05:42:00 +0000 (07:42 +0200)
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2998)

crypto/ex_data.c

index d947f3edac4bd0dafa46075d1e4e2af113625b4a..108a1959eacfc27b623e7d2383d9722ab945c69f 100644 (file)
@@ -459,7 +459,7 @@ static int int_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
                            CRYPTO_EX_DATA *from)
 {
     int mx, j, i;
-    char *ptr;
+    void *ptr;
     CRYPTO_EX_DATA_FUNCS **storage = NULL;
     EX_CLASS_ITEM *item;
     if (!from->sk)
@@ -473,6 +473,8 @@ static int int_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
     if (j < mx)
         mx = j;
     if (mx > 0) {
+        if (!CRYPTO_set_ex_data(to, mx - 1, NULL))
+            goto skip;
         storage = OPENSSL_malloc(mx * sizeof(CRYPTO_EX_DATA_FUNCS *));
         if (!storage)
             goto skip;