]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
test/evp_test.c: Add check for OPENSSL_strdup
authorJiasheng Jiang <jiasheng@iscas.ac.cn>
Fri, 17 Jun 2022 08:57:15 +0000 (16:57 +0800)
committerPauli <pauli@openssl.org>
Wed, 22 Jun 2022 07:00:33 +0000 (17:00 +1000)
As the potential failure of the OPENSSL_strdup(),
it should be better to check the return value and
return error if fails.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18592)

test/evp_test.c

index 5d51c47ef5ca2ab7b6009fe6f208de5792e93ef6..c7f76df3598fc3ca40ddc0ac1632c12e8e26646d 100644 (file)
@@ -1256,7 +1256,7 @@ static int mac_test_parse(EVP_TEST *t,
         return parse_bin(value, &mdata->salt, &mdata->salt_len);
     if (strcmp(keyword, "Algorithm") == 0) {
         mdata->alg = OPENSSL_strdup(value);
-        if (!mdata->alg)
+        if (mdata->alg == NULL)
             return -1;
         return 1;
     }
@@ -1268,9 +1268,13 @@ static int mac_test_parse(EVP_TEST *t,
         return mdata->xof = 1;
     if (strcmp(keyword, "NoReinit") == 0)
         return mdata->no_reinit = 1;
-    if (strcmp(keyword, "Ctrl") == 0)
-        return sk_OPENSSL_STRING_push(mdata->controls,
-                                      OPENSSL_strdup(value)) != 0;
+    if (strcmp(keyword, "Ctrl") == 0) {
+        char *data = OPENSSL_strdup(value);
+
+        if (data == NULL)
+            return -1;
+        return sk_OPENSSL_STRING_push(mdata->controls, data) != 0;
+    }
     if (strcmp(keyword, "OutputSize") == 0) {
         mdata->output_size = atoi(value);
         if (mdata->output_size < 0)