test/sslapitest.c: Add check for SSL_CTX_new
authorJiasheng Jiang <jiasheng@iscas.ac.cn>
Mon, 21 Feb 2022 02:54:29 +0000 (10:54 +0800)
committerPauli <pauli@openssl.org>
Tue, 22 Feb 2022 23:21:27 +0000 (10:21 +1100)
As the potential failure of the memory allocation, it should
be better to check the return value of SSL_CTX_new() and return
error if fails, like SSL_CTX_new_ex().

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17739)

test/sslapitest.c

index 181d0ef686fd4d8ecd33bb27ccacac70c7b57a03..8ba5d8125c8f3f29de490e3ed9bbf78a89929552 100644 (file)
@@ -8090,8 +8090,12 @@ static int test_cert_cb_int(int prot, int tst)
     else
         cert_cb_cnt = 0;
 
-    if (tst == 2)
+    if (tst == 2) {
         snictx = SSL_CTX_new(TLS_server_method());
+        if (!TEST_ptr(snictx))
+            goto end;
+    }
+
     SSL_CTX_set_cert_cb(sctx, cert_cb, snictx);
 
     if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,