diff options
author | tb <> | 2024-10-03 04:15:52 +0000 |
---|---|---|
committer | tb <> | 2024-10-03 04:15:52 +0000 |
commit | 160339210bf97ab2ac1a1d10c353c17e23c259b0 (patch) | |
tree | db8a36454e159f91515405f5d4b24d245b794363 /src | |
parent | da7b0f4bfa71c9b8be4c449be0da83036941e3a2 (diff) | |
download | openbsd-160339210bf97ab2ac1a1d10c353c17e23c259b0.tar.gz openbsd-160339210bf97ab2ac1a1d10c353c17e23c259b0.tar.bz2 openbsd-160339210bf97ab2ac1a1d10c353c17e23c259b0.zip |
Fix BN_to_ASN1_INTEGER() misuse
You can either let this API reuse an existing ASN1_INTEGER or you can let
it allocate a new one. If you try to do both at the same time, you'll leak.
ok jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/ec/ec_asn1.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/lib/libcrypto/ec/ec_asn1.c b/src/lib/libcrypto/ec/ec_asn1.c index 2ce7d785c4..504948b237 100644 --- a/src/lib/libcrypto/ec/ec_asn1.c +++ b/src/lib/libcrypto/ec/ec_asn1.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_asn1.c,v 1.53 2024/04/17 23:24:18 tb Exp $ */ | 1 | /* $OpenBSD: ec_asn1.c,v 1.54 2024/10/03 04:15:52 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -760,20 +760,19 @@ ec_asn1_group2parameters(const EC_GROUP *group, ECPARAMETERS *param) | |||
760 | ECerror(ERR_R_ASN1_LIB); | 760 | ECerror(ERR_R_ASN1_LIB); |
761 | goto err; | 761 | goto err; |
762 | } | 762 | } |
763 | /* set the order */ | ||
764 | if (!EC_GROUP_get_order(group, tmp, NULL)) { | 763 | if (!EC_GROUP_get_order(group, tmp, NULL)) { |
765 | ECerror(ERR_R_EC_LIB); | 764 | ECerror(ERR_R_EC_LIB); |
766 | goto err; | 765 | goto err; |
767 | } | 766 | } |
768 | ret->order = BN_to_ASN1_INTEGER(tmp, ret->order); | 767 | ASN1_INTEGER_free(ret->order); |
769 | if (ret->order == NULL) { | 768 | if ((ret->order = BN_to_ASN1_INTEGER(tmp, NULL)) == NULL) { |
770 | ECerror(ERR_R_ASN1_LIB); | 769 | ECerror(ERR_R_ASN1_LIB); |
771 | goto err; | 770 | goto err; |
772 | } | 771 | } |
773 | /* set the cofactor (optional) */ | 772 | ASN1_INTEGER_free(ret->cofactor); |
773 | ret->cofactor = NULL; | ||
774 | if (EC_GROUP_get_cofactor(group, tmp, NULL)) { | 774 | if (EC_GROUP_get_cofactor(group, tmp, NULL)) { |
775 | ret->cofactor = BN_to_ASN1_INTEGER(tmp, ret->cofactor); | 775 | if ((ret->cofactor = BN_to_ASN1_INTEGER(tmp, NULL)) == NULL) { |
776 | if (ret->cofactor == NULL) { | ||
777 | ECerror(ERR_R_ASN1_LIB); | 776 | ECerror(ERR_R_ASN1_LIB); |
778 | goto err; | 777 | goto err; |
779 | } | 778 | } |