]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
openssl rehash: add check for OPENSSL_strdup
authorJiasheng Jiang <jiasheng@iscas.ac.cn>
Thu, 10 Feb 2022 03:21:47 +0000 (11:21 +0800)
committerTomas Mraz <tomas@openssl.org>
Mon, 14 Feb 2022 09:03:42 +0000 (10:03 +0100)
As the potential failure of the memory allocation,
it should be better to check the return value of
OPENSSL_strdup() and return error if fails.
Also, we need to restore the 'ep' to be NULL if fails.

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

apps/rehash.c

index e0cdc9bc622f99282cc78cf6f8d1a4e7c6a95116..e0b795460784446b4388cc0f0bf4ed507897edc3 100644 (file)
@@ -168,6 +168,12 @@ static int add_entry(enum Type type, unsigned int hash, const char *filename,
         *ep = nilhentry;
         ep->old_id = ~0;
         ep->filename = OPENSSL_strdup(filename);
+        if (ep->filename == NULL) {
+            OPENSSL_free(ep);
+            ep = NULL;
+            BIO_printf(bio_err, "out of memory\n");
+            return 1;
+        }
         if (bp->last_entry)
             bp->last_entry->next = ep;
         if (bp->first_entry == NULL)