diff options
| author | tb <> | 2026-09-02 07:08:36 +0000 |
|---|---|---|
| committer | tb <> | 2026-09-02 07:08:36 +0000 |
| commit | b5b8cb6169521cf1c75580c5beb54a0b73232716 (patch) | |
| tree | b24c13e28132bd1c15bbfdd696eb8b61852906b2 /src/lib | |
| parent | 737e77df570ee08793d343c8c1fca9ac83ac9d80 (diff) | |
| download | openbsd-b5b8cb6169521cf1c75580c5beb54a0b73232716.tar.gz openbsd-b5b8cb6169521cf1c75580c5beb54a0b73232716.tar.bz2 openbsd-b5b8cb6169521cf1c75580c5beb54a0b73232716.zip | |
asn1_multi: rework creation of the returned stack
Currently, the ASN1_TYPE ret is created up front and further populated
via a possibly failing call to ASN1_STRING_type_new(). On failure, the
incomplete ret is returned, indicating success to the caller, which may
or may not fail later.
Instead, create the inner ASN1_STRING first, then the ASN1_TYPE. Use
setter API with proper ownership transfer rather than fiddling with
deeply nested ASN1 structures. This way we only succeed if everything
actually succeeded.
ok kenjiro
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/libcrypto/asn1/asn1_gen.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_gen.c b/src/lib/libcrypto/asn1/asn1_gen.c index 0918b6aefc..a8b91d3b3d 100644 --- a/src/lib/libcrypto/asn1/asn1_gen.c +++ b/src/lib/libcrypto/asn1/asn1_gen.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: asn1_gen.c,v 1.30 2026/09/02 07:04:56 tb Exp $ */ | 1 | /* $OpenBSD: asn1_gen.c,v 1.31 2026/09/02 07:08:36 tb Exp $ */ |
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 3 | * project 2002. | 3 | * project 2002. |
| 4 | */ | 4 | */ |
| @@ -437,6 +437,7 @@ static ASN1_TYPE * | |||
| 437 | asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | 437 | asn1_multi(int utype, const char *section, X509V3_CTX *cnf) |
| 438 | { | 438 | { |
| 439 | ASN1_TYPE *ret = NULL, *typ = NULL; | 439 | ASN1_TYPE *ret = NULL, *typ = NULL; |
| 440 | ASN1_STRING *astr = NULL; | ||
| 440 | STACK_OF(ASN1_TYPE) *sk = NULL; | 441 | STACK_OF(ASN1_TYPE) *sk = NULL; |
| 441 | STACK_OF(CONF_VALUE) *sect = NULL; | 442 | STACK_OF(CONF_VALUE) *sect = NULL; |
| 442 | unsigned char *der = NULL; | 443 | unsigned char *der = NULL; |
| @@ -471,23 +472,25 @@ asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | |||
| 471 | if (derlen < 0) | 472 | if (derlen < 0) |
| 472 | goto bad; | 473 | goto bad; |
| 473 | 474 | ||
| 474 | if (!(ret = ASN1_TYPE_new())) | 475 | if ((astr = ASN1_STRING_type_new(utype)) == NULL) |
| 475 | goto bad; | 476 | goto bad; |
| 477 | ASN1_STRING_set0(astr, der, derlen); | ||
| 478 | der = NULL; | ||
| 479 | derlen = 0; | ||
| 476 | 480 | ||
| 477 | if (!(ret->value.asn1_string = ASN1_STRING_type_new(utype))) | 481 | if ((typ = ASN1_TYPE_new()) == NULL) |
| 478 | goto bad; | 482 | goto bad; |
| 483 | ASN1_TYPE_set(typ, utype, astr); | ||
| 484 | astr = NULL; | ||
| 479 | 485 | ||
| 480 | ret->type = utype; | 486 | ret = typ; |
| 481 | 487 | typ = NULL; | |
| 482 | ret->value.asn1_string->data = der; | ||
| 483 | ret->value.asn1_string->length = derlen; | ||
| 484 | |||
| 485 | der = NULL; | ||
| 486 | 488 | ||
| 487 | bad: | 489 | bad: |
| 488 | free(der); | 490 | free(der); |
| 489 | sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free); | 491 | sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free); |
| 490 | ASN1_TYPE_free(typ); | 492 | ASN1_TYPE_free(typ); |
| 493 | ASN1_STRING_free(astr); | ||
| 491 | 494 | ||
| 492 | return ret; | 495 | return ret; |
| 493 | } | 496 | } |
