check the return value of CRYPTO_strdup()
authorxkernel <xkernel.wang@foxmail.com>
Mon, 21 Feb 2022 07:17:46 +0000 (15:17 +0800)
committerPauli <pauli@openssl.org>
Mon, 28 Feb 2022 08:28:22 +0000 (19:28 +1100)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17741)

(cherry picked from commit 37be6feeebfec87733e5cb4762fc12bebba9f124)

apps/req.c
apps/s_client.c

index fd9826a5a8df2f58cbd219748eb7ae3c49f1fa71..8d6653f3493b10b1538834ceae9596691250d504 100644 (file)
@@ -1594,6 +1594,13 @@ static EVP_PKEY_CTX *set_keygen_ctx(const char *gstr,
         *pkeytype = OPENSSL_strndup(keytype, keytypelen);
     else
         *pkeytype = OPENSSL_strdup(keytype);
+
+    if (*pkeytype == NULL) {
+        BIO_printf(bio_err, "Out of memory\n");
+        EVP_PKEY_free(param);
+        return NULL;
+    }
+
     if (keylen >= 0)
         *pkeylen = keylen;
 
index 3240467fb22aee5a2bf9d91908b3e8949b1c29d9..e16f539e46a9253be686240928017fa76da47a34 100644 (file)
@@ -805,7 +805,7 @@ int s_client_main(int argc, char **argv)
     char *cert_file = NULL, *key_file = NULL, *chain_file = NULL;
     char *chCApath = NULL, *chCAfile = NULL, *chCAstore = NULL, *host = NULL;
     char *thost = NULL, *tport = NULL;
-    char *port = OPENSSL_strdup(PORT);
+    char *port = NULL;
     char *bindhost = NULL, *bindport = NULL;
     char *passarg = NULL, *pass = NULL;
     char *vfyCApath = NULL, *vfyCAfile = NULL, *vfyCAstore = NULL;
@@ -904,10 +904,11 @@ int s_client_main(int argc, char **argv)
     c_debug = 0;
     c_showcerts = 0;
     c_nbio = 0;
+    port = OPENSSL_strdup(PORT);
     vpm = X509_VERIFY_PARAM_new();
     cctx = SSL_CONF_CTX_new();
 
-    if (vpm == NULL || cctx == NULL) {
+    if (port == NULL || vpm == NULL || cctx == NULL) {
         BIO_printf(bio_err, "%s: out of memory\n", opt_getprog());
         goto end;
     }