]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
test: avoid memory leaks on errors
authorPauli <pauli@openssl.org>
Fri, 25 Jun 2021 02:57:37 +0000 (12:57 +1000)
committerPauli <pauli@openssl.org>
Sat, 26 Jun 2021 01:33:52 +0000 (11:33 +1000)
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/15910)

test/conf_include_test.c
test/helpers/handshake.c
test/sslapitest.c

index 1c00c601e5984712cf390f6362167e6cf0c094e9..2481a2380b7643962d97683e737a5665d768f63e 100644 (file)
@@ -42,7 +42,7 @@ static int change_path(const char *file)
     char *s = OPENSSL_strdup(file);
     char *p = s;
     char *last = NULL;
-    int ret;
+    int ret = 0;
 
     if (s == NULL)
         return -1;
@@ -51,11 +51,12 @@ static int change_path(const char *file)
         last = p++;
     }
     if (last == NULL)
-        return 0;
+        goto err;
     last[DIRSEP_PRESERVE] = 0;
 
     TEST_note("changing path to %s", s);
     ret = chdir(s);
+ err:
     OPENSSL_free(s);
     return ret;
 }
index 0543634c73d48f7266200b2f7f17947f880f5300..d44aa4baafe23b0448fddb1c84973c121ff181c8 100644 (file)
@@ -278,8 +278,10 @@ static int server_ocsp_cb(SSL *s, void *arg)
      * For the purposes of testing we just send back a dummy OCSP response
      */
     *resp = *(unsigned char *)arg;
-    if (!SSL_set_tlsext_status_ocsp_resp(s, resp, 1))
+    if (!SSL_set_tlsext_status_ocsp_resp(s, resp, 1)) {
+        OPENSSL_free(resp);
         return SSL_TLSEXT_ERR_ALERT_FATAL;
+    }
 
     return SSL_TLSEXT_ERR_OK;
 }
index 850c941ac248d6a5782c18c106e93fe11cf6d767..bbb1cf91f40db0137ab961f804e59a63350c42b8 100644 (file)
@@ -1644,7 +1644,11 @@ static int ocsp_server_cb(SSL *s, void *arg)
     if (!TEST_ptr(copy = OPENSSL_memdup(orespder, sizeof(orespder))))
         return SSL_TLSEXT_ERR_ALERT_FATAL;
 
-    SSL_set_tlsext_status_ocsp_resp(s, copy, sizeof(orespder));
+    if (!TEST_true(SSL_set_tlsext_status_ocsp_resp(s, copy,
+                                                   sizeof(orespder)))) {
+        OPENSSL_free(copy);
+        return SSL_TLSEXT_ERR_ALERT_FATAL;
+    }
     ocsp_server_called = 1;
     return SSL_TLSEXT_ERR_OK;
 }