diff options
author | tb <> | 2023-03-06 19:10:14 +0000 |
---|---|---|
committer | tb <> | 2023-03-06 19:10:14 +0000 |
commit | 94300da894e5468bd62ec59554e63c4ce7b63037 (patch) | |
tree | d896c741c44641a8bf70fb36b25fbd316f337a43 | |
parent | 6c965e26b1a93da63948edae6b68564be1ded507 (diff) | |
download | openbsd-94300da894e5468bd62ec59554e63c4ce7b63037.tar.gz openbsd-94300da894e5468bd62ec59554e63c4ce7b63037.tar.bz2 openbsd-94300da894e5468bd62ec59554e63c4ce7b63037.zip |
Clean up ndef_{prefix,suffix}_free()
These functions are rather similar, so there's no need for the code to
be wildly different. Add a missing NULL check to ndef_prefix_free() since
that will be needed in a subsequent commit.
ok jsing
-rw-r--r-- | src/lib/libcrypto/asn1/bio_ndef.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/lib/libcrypto/asn1/bio_ndef.c b/src/lib/libcrypto/asn1/bio_ndef.c index 88b204e8aa..6266d68bbd 100644 --- a/src/lib/libcrypto/asn1/bio_ndef.c +++ b/src/lib/libcrypto/asn1/bio_ndef.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bio_ndef.c,v 1.11 2021/12/25 13:17:48 jsing Exp $ */ | 1 | /* $OpenBSD: bio_ndef.c,v 1.12 2023/03/06 19:10:14 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. | 3 | * project. |
4 | */ | 4 | */ |
@@ -178,29 +178,34 @@ ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg) | |||
178 | static int | 178 | static int |
179 | ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) | 179 | ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) |
180 | { | 180 | { |
181 | NDEF_SUPPORT *ndef_aux; | 181 | NDEF_SUPPORT **pndef_aux = parg; |
182 | 182 | ||
183 | if (!parg) | 183 | if (pndef_aux == NULL || *pndef_aux == NULL) |
184 | return 0; | 184 | return 0; |
185 | 185 | ||
186 | ndef_aux = *(NDEF_SUPPORT **)parg; | 186 | free((*pndef_aux)->derbuf); |
187 | (*pndef_aux)->derbuf = NULL; | ||
187 | 188 | ||
188 | free(ndef_aux->derbuf); | ||
189 | |||
190 | ndef_aux->derbuf = NULL; | ||
191 | *pbuf = NULL; | 189 | *pbuf = NULL; |
192 | *plen = 0; | 190 | *plen = 0; |
191 | |||
193 | return 1; | 192 | return 1; |
194 | } | 193 | } |
195 | 194 | ||
196 | static int | 195 | static int |
197 | ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) | 196 | ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) |
198 | { | 197 | { |
199 | NDEF_SUPPORT **pndef_aux = (NDEF_SUPPORT **)parg; | 198 | NDEF_SUPPORT **pndef_aux = parg; |
199 | |||
200 | /* Ensure ndef_prefix_free() won't fail, so we won't leak *pndef_aux. */ | ||
201 | if (pndef_aux == NULL || *pndef_aux == NULL) | ||
202 | return 0; | ||
200 | if (!ndef_prefix_free(b, pbuf, plen, parg)) | 203 | if (!ndef_prefix_free(b, pbuf, plen, parg)) |
201 | return 0; | 204 | return 0; |
205 | |||
202 | free(*pndef_aux); | 206 | free(*pndef_aux); |
203 | *pndef_aux = NULL; | 207 | *pndef_aux = NULL; |
208 | |||
204 | return 1; | 209 | return 1; |
205 | } | 210 | } |
206 | 211 | ||