Don't leak EVP_KDF_CTX on error
authorMatt Caswell <matt@openssl.org>
Sun, 17 Feb 2019 16:13:08 +0000 (16:13 +0000)
committerMatt Caswell <matt@openssl.org>
Mon, 18 Feb 2019 09:44:09 +0000 (09:44 +0000)
Found by Coverity

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/8260)

crypto/evp/pbe_scrypt.c

index f8ea1fab382a1dd25d65db41bee8a8f3ae3635ec..722402528a8e81b41ee01319fb4e0f463a09b3a5 100644 (file)
@@ -41,6 +41,11 @@ int EVP_PBE_scrypt(const char *pass, size_t passlen,
     int rv = 1;
     EVP_KDF_CTX *kctx;
 
+    if (r > UINT32_MAX || p > UINT32_MAX) {
+        EVPerr(EVP_F_EVP_PBE_SCRYPT, EVP_R_PARAMETER_TOO_LARGE);
+        return 0;
+    }
+
     /* Maintain existing behaviour. */
     if (pass == NULL) {
         pass = empty;
@@ -53,10 +58,6 @@ int EVP_PBE_scrypt(const char *pass, size_t passlen,
     if (kctx == NULL)
         return 0;
 
-    if (r > UINT32_MAX || p > UINT32_MAX) {
-        EVPerr(EVP_F_EVP_PBE_SCRYPT, EVP_R_PARAMETER_TOO_LARGE);
-        return 0;
-    }
     if (EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_PASS, pass, (size_t)passlen) != 1
             || EVP_KDF_ctrl(kctx, EVP_KDF_CTRL_SET_SALT,
                             salt, (size_t)saltlen) != 1