From 79cda38cff834224fb9d86dc7433b4f60688ce49 Mon Sep 17 00:00:00 2001 From: Jiasheng Jiang Date: Thu, 10 Feb 2022 11:21:47 +0800 Subject: [PATCH] openssl rehash: add check for OPENSSL_strdup 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 Reviewed-by: Paul Dale Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/17676) --- apps/rehash.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/rehash.c b/apps/rehash.c index e0cdc9bc622..e0b79546078 100644 --- a/apps/rehash.c +++ b/apps/rehash.c @@ -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) -- 2.47.3