check the return value of BN_new() and BN_dup()
authorx2018 <xkernel.wang@foxmail.com>
Mon, 1 Nov 2021 12:36:54 +0000 (20:36 +0800)
committerTomas Mraz <tomas@openssl.org>
Wed, 3 Nov 2021 13:28:23 +0000 (14:28 +0100)
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16948)

test/testutil/tests.c

index cb3f77f14a1b077e42369675551d25da12c83c04..b431657e056d4564264e7d899787691e34d70ca0 100644 (file)
@@ -417,8 +417,8 @@ int test_BN_eq_word(const char *file, int line, const char *bns, const char *ws,
 
     if (a != NULL && BN_is_word(a, w))
         return 1;
-    bw = BN_new();
-    BN_set_word(bw, w);
+    if ((bw = BN_new()) != NULL)
+        BN_set_word(bw, w);
     test_fail_bignum_message(NULL, file, line, "BIGNUM", bns, ws, "==", a, bw);
     BN_free(bw);
     return 0;
@@ -431,10 +431,10 @@ int test_BN_abs_eq_word(const char *file, int line, const char *bns,
 
     if (a != NULL && BN_abs_is_word(a, w))
         return 1;
-    bw = BN_new();
-    aa = BN_dup(a);
-    BN_set_negative(aa, 0);
-    BN_set_word(bw, w);
+    if ((aa = BN_dup(a)) != NULL)
+        BN_set_negative(aa, 0);
+    if ((bw = BN_new()) != NULL)
+        BN_set_word(bw, w);
     test_fail_bignum_message(NULL, file, line, "BIGNUM", bns, ws, "abs==",
                              aa, bw);
     BN_free(bw);