summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorBernd Edlinger <bernd.edlinger@hotmail.de>2023-12-10 10:18:19 +0100
committerTomas Mraz <tomas@openssl.org>2023-12-12 13:43:46 +0100
commitade7b081e565f46526d95c25be43927c2f988ae2 (patch)
tree98860e476b9d81463d5e76d00b37a7b0e47c415a /crypto
parent250990ea8eb3e16ce988eda01e10096a3d5365c4 (diff)
Fix a possible memory leak in do_othername
Since the gen->type will not be set in a2i_GENERAL_NAME the gen->d.otherName will not be automatically cleaned up by GENERAL_NAME_free. Also fixed a similar leak in a2i_GENERAL_NAME, where ASN1_STRING_set may fail but gen->d.ia5 will not be automatically cleaned up. Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22996) (cherry picked from commit 1c078212f1548d7f647a1f0f12ed6df257c85cc3)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/x509/v3_san.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/crypto/x509/v3_san.c b/crypto/x509/v3_san.c
index 7798505eec..9adf494707 100644
--- a/crypto/x509/v3_san.c
+++ b/crypto/x509/v3_san.c
@@ -581,6 +581,8 @@ GENERAL_NAME *a2i_GENERAL_NAME(GENERAL_NAME *out,
if ((gen->d.ia5 = ASN1_IA5STRING_new()) == NULL ||
!ASN1_STRING_set(gen->d.ia5, (unsigned char *)value,
strlen(value))) {
+ ASN1_IA5STRING_free(gen->d.ia5);
+ gen->d.ia5 = NULL;
ERR_raise(ERR_LIB_X509V3, ERR_R_ASN1_LIB);
goto err;
}
@@ -651,16 +653,21 @@ static int do_othername(GENERAL_NAME *gen, const char *value, X509V3_CTX *ctx)
*/
ASN1_TYPE_free(gen->d.otherName->value);
if ((gen->d.otherName->value = ASN1_generate_v3(p + 1, ctx)) == NULL)
- return 0;
+ goto err;
objlen = p - value;
objtmp = OPENSSL_strndup(value, objlen);
if (objtmp == NULL)
- return 0;
+ goto err;
gen->d.otherName->type_id = OBJ_txt2obj(objtmp, 0);
OPENSSL_free(objtmp);
if (!gen->d.otherName->type_id)
- return 0;
+ goto err;
return 1;
+
+ err:
+ OTHERNAME_free(gen->d.otherName);
+ gen->d.otherName = NULL;
+ return 0;
}
static int do_dirname(GENERAL_NAME *gen, const char *value, X509V3_CTX *ctx)