diff options
| author | tb <> | 2023-07-09 19:22:43 +0000 |
|---|---|---|
| committer | tb <> | 2023-07-09 19:22:43 +0000 |
| commit | 839c3ea11171d86f26bbd45c967b4967b8b939cc (patch) | |
| tree | 0722cc48611bcbbb8daa2bd8351b49f109c90264 | |
| parent | a42962dca443b7ca250bbb692c03696ccd25c545 (diff) | |
| download | openbsd-839c3ea11171d86f26bbd45c967b4967b8b939cc.tar.gz openbsd-839c3ea11171d86f26bbd45c967b4967b8b939cc.tar.bz2 openbsd-839c3ea11171d86f26bbd45c967b4967b8b939cc.zip | |
Fix ndef_{prefix,suffix}()
These functions inline a poor version of asn1_item_flags_i2d() without
error checks. This can be replaced with a single correct call to
ASN1_item_ndef_i2d(). Mechanically adding malloc checks and checks for
negative did not really improve things all that much in a related project.
ok beck jsing
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/asn1/bio_ndef.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/lib/libcrypto/asn1/bio_ndef.c b/src/lib/libcrypto/asn1/bio_ndef.c index d0329ede8f..11e51edade 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.22 2023/04/25 19:08:30 tb Exp $ */ | 1 | /* $OpenBSD: bio_ndef.c,v 1.23 2023/07/09 19:22:43 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 | */ |
| @@ -171,7 +171,7 @@ static int | |||
| 171 | ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg) | 171 | ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg) |
| 172 | { | 172 | { |
| 173 | NDEF_SUPPORT *ndef_aux; | 173 | NDEF_SUPPORT *ndef_aux; |
| 174 | unsigned char *p; | 174 | unsigned char *p = NULL; |
| 175 | int derlen; | 175 | int derlen; |
| 176 | 176 | ||
| 177 | if (!parg) | 177 | if (!parg) |
| @@ -179,13 +179,13 @@ ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg) | |||
| 179 | 179 | ||
| 180 | ndef_aux = *(NDEF_SUPPORT **)parg; | 180 | ndef_aux = *(NDEF_SUPPORT **)parg; |
| 181 | 181 | ||
| 182 | derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it); | 182 | if ((derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it)) <= 0) |
| 183 | p = malloc(derlen); | 183 | return 0; |
| 184 | |||
| 184 | ndef_aux->derbuf = p; | 185 | ndef_aux->derbuf = p; |
| 185 | *pbuf = p; | 186 | *pbuf = p; |
| 186 | derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it); | ||
| 187 | 187 | ||
| 188 | if (!*ndef_aux->boundary) | 188 | if (*ndef_aux->boundary == NULL) |
| 189 | return 0; | 189 | return 0; |
| 190 | 190 | ||
| 191 | *plen = *ndef_aux->boundary - *pbuf; | 191 | *plen = *ndef_aux->boundary - *pbuf; |
| @@ -231,7 +231,7 @@ static int | |||
| 231 | ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg) | 231 | ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg) |
| 232 | { | 232 | { |
| 233 | NDEF_SUPPORT *ndef_aux; | 233 | NDEF_SUPPORT *ndef_aux; |
| 234 | unsigned char *p; | 234 | unsigned char *p = NULL; |
| 235 | int derlen; | 235 | int derlen; |
| 236 | const ASN1_AUX *aux; | 236 | const ASN1_AUX *aux; |
| 237 | ASN1_STREAM_ARG sarg; | 237 | ASN1_STREAM_ARG sarg; |
| @@ -251,14 +251,15 @@ ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg) | |||
| 251 | &ndef_aux->val, ndef_aux->it, &sarg) <= 0) | 251 | &ndef_aux->val, ndef_aux->it, &sarg) <= 0) |
| 252 | return 0; | 252 | return 0; |
| 253 | 253 | ||
| 254 | derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it); | 254 | if ((derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it)) <= 0) |
| 255 | p = malloc(derlen); | 255 | return 0; |
| 256 | |||
| 256 | ndef_aux->derbuf = p; | 257 | ndef_aux->derbuf = p; |
| 257 | *pbuf = p; | 258 | *pbuf = p; |
| 258 | derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it); | ||
| 259 | 259 | ||
| 260 | if (!*ndef_aux->boundary) | 260 | if (*ndef_aux->boundary == NULL) |
| 261 | return 0; | 261 | return 0; |
| 262 | |||
| 262 | *pbuf = *ndef_aux->boundary; | 263 | *pbuf = *ndef_aux->boundary; |
| 263 | *plen = derlen - (*ndef_aux->boundary - ndef_aux->derbuf); | 264 | *plen = derlen - (*ndef_aux->boundary - ndef_aux->derbuf); |
| 264 | 265 | ||
