diff options
author | tb <> | 2024-12-11 11:22:06 +0000 |
---|---|---|
committer | tb <> | 2024-12-11 11:22:06 +0000 |
commit | 9b082e3d93019c6ea59a61073a6eba48ace641b8 (patch) | |
tree | 2b9df34d0b7105df887b2e6eed474f8d783767bf /src | |
parent | d87deb6ad0f26124c4c49ac4d9699a8be4a0ea8c (diff) | |
download | openbsd-9b082e3d93019c6ea59a61073a6eba48ace641b8.tar.gz openbsd-9b082e3d93019c6ea59a61073a6eba48ace641b8.tar.bz2 openbsd-9b082e3d93019c6ea59a61073a6eba48ace641b8.zip |
Avoid an oob access in asn1_item_free()
As explained in a comment, this needs to loop backwards and the last tt--
ends up pointing at &it->templates[-1], which isn't ok. Use a simple way
of looping, which is also ugly and involves some type confusion as pointed
out by claudio. However, type confusion is common in libcrypto's asn1 code
and won't be fixed anytime soon anyway.
ok jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/asn1/tasn_fre.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/lib/libcrypto/asn1/tasn_fre.c b/src/lib/libcrypto/asn1/tasn_fre.c index 83c073b55d..0e259a13ab 100644 --- a/src/lib/libcrypto/asn1/tasn_fre.c +++ b/src/lib/libcrypto/asn1/tasn_fre.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tasn_fre.c,v 1.23 2023/07/28 10:00:10 tb Exp $ */ | 1 | /* $OpenBSD: tasn_fre.c,v 1.24 2024/12/11 11:22:06 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 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -152,10 +152,9 @@ asn1_item_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
152 | * determine the type of the field it defines. So | 152 | * determine the type of the field it defines. So |
153 | * free up in reverse order. | 153 | * free up in reverse order. |
154 | */ | 154 | */ |
155 | tt = it->templates + it->tcount - 1; | 155 | for (i = it->tcount - 1; i >= 0; i--) { |
156 | for (i = 0; i < it->tcount; tt--, i++) { | ||
157 | ASN1_VALUE **pseqval; | 156 | ASN1_VALUE **pseqval; |
158 | seqtt = asn1_do_adb(pval, tt, 0); | 157 | seqtt = asn1_do_adb(pval, &it->templates[i], 0); |
159 | if (!seqtt) | 158 | if (!seqtt) |
160 | continue; | 159 | continue; |
161 | pseqval = asn1_get_field_ptr(pval, seqtt); | 160 | pseqval = asn1_get_field_ptr(pval, seqtt); |