Set salt length after the malloc has succeeded
authorAlessandro Ghedini <alessandro@ghedini.me>
Thu, 8 Oct 2015 12:39:58 +0000 (14:39 +0200)
committerRichard Levitte <levitte@openssl.org>
Fri, 23 Oct 2015 17:52:08 +0000 (19:52 +0200)
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
crypto/pkcs12/p12_mutl.c

index 9da65fe..4cf68e1 100644 (file)
@@ -208,11 +208,11 @@ int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, int saltlen,
     }
     if (!saltlen)
         saltlen = PKCS12_SALT_LEN;
-    p12->mac->salt->length = saltlen;
     if ((p12->mac->salt->data = OPENSSL_malloc(saltlen)) == NULL) {
         PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
         return 0;
     }
+    p12->mac->salt->length = saltlen;
     if (!salt) {
         if (RAND_bytes(p12->mac->salt->data, saltlen) <= 0)
             return 0;