From: Andy Polyakov Date: Sun, 8 Oct 2017 18:10:13 +0000 (+0200) Subject: crypto/x509v3/v3_utl.c: fix Coverity problems. X-Git-Tag: OpenSSL_1_1_0g~19 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a5034bea281e3b6b79a4ad33c2471afee483d6bc;p=oweals%2Fopenssl.git crypto/x509v3/v3_utl.c: fix Coverity problems. Reviewed-by: Rich Salz (Merged from https://github.com/openssl/openssl/pull/4492) (cherry picked from commit 32f3b98d1302d4c0950dc1bf94b50269b6edbd95) Reviewed-by: Rich Salz Reviewed-by: Richard Levitte Reviewed-by: Bernd Edlinger (Merged from https://github.com/openssl/openssl/pull/4514) --- diff --git a/crypto/x509v3/v3_utl.c b/crypto/x509v3/v3_utl.c index 7dc9a4533e..adc1552490 100644 --- a/crypto/x509v3/v3_utl.c +++ b/crypto/x509v3/v3_utl.c @@ -37,6 +37,7 @@ int X509V3_add_value(const char *name, const char *value, { CONF_VALUE *vtmp = NULL; char *tname = NULL, *tvalue = NULL; + int sk_allocated = (*extlist == NULL); if (name && (tname = OPENSSL_strdup(name)) == NULL) goto err; @@ -44,7 +45,7 @@ int X509V3_add_value(const char *name, const char *value, goto err; if ((vtmp = OPENSSL_malloc(sizeof(*vtmp))) == NULL) goto err; - if (*extlist == NULL && (*extlist = sk_CONF_VALUE_new_null()) == NULL) + if (sk_allocated && (*extlist = sk_CONF_VALUE_new_null()) == NULL) goto err; vtmp->section = NULL; vtmp->name = tname; @@ -54,6 +55,8 @@ int X509V3_add_value(const char *name, const char *value, return 1; err: X509V3err(X509V3_F_X509V3_ADD_VALUE, ERR_R_MALLOC_FAILURE); + if (sk_allocated) + sk_CONF_VALUE_free(*extlist); OPENSSL_free(vtmp); OPENSSL_free(tname); OPENSSL_free(tvalue);