summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiasheng Jiang <jiasheng@iscas.ac.cn>2022-02-10 11:21:47 +0800
committerTomas Mraz <tomas@openssl.org>2022-02-14 10:03:42 +0100
commit79cda38cff834224fb9d86dc7433b4f60688ce49 (patch)
tree431b0474afb48d691428424da5fa89495e56c4f0
parentbb2fb5d7cc6c4abc888c3fd6df4366b6dfde25a6 (diff)
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 <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)
-rw-r--r--apps/rehash.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/apps/rehash.c b/apps/rehash.c
index e0cdc9bc62..e0b7954607 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)