summaryrefslogtreecommitdiffstats
path: root/apps
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:04:09 +0100
commite2387e6bd4ee69e0702d1a489045b72632b91e48 (patch)
tree757b16ce098a69111357df4cfd4e779a98be7655 /apps
parentcfbcfe86c2ccdd308fc6fa3d3245dd6eb5774b0e (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) (cherry picked from commit 79cda38cff834224fb9d86dc7433b4f60688ce49)
Diffstat (limited to 'apps')
-rw-r--r--apps/rehash.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/apps/rehash.c b/apps/rehash.c
index 7fe01de11c..ae91654fe9 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)