diff options
| author | jsing <> | 2021-12-20 17:23:07 +0000 |
|---|---|---|
| committer | jsing <> | 2021-12-20 17:23:07 +0000 |
| commit | ee3f28de4787fb4c05a0e852fb93ba9ea9bda5fa (patch) | |
| tree | 7cd276cd2f156b52ba6579e7e3fc8a3e60628998 | |
| parent | ca979bc13681324bec56d478f460b8950d2b849d (diff) | |
| download | openbsd-ee3f28de4787fb4c05a0e852fb93ba9ea9bda5fa.tar.gz openbsd-ee3f28de4787fb4c05a0e852fb93ba9ea9bda5fa.tar.bz2 openbsd-ee3f28de4787fb4c05a0e852fb93ba9ea9bda5fa.zip | |
Always allocate a new stack in o2i_SCT_LIST().
If we're given a pointer to an existing stack, free it and allocate a new
one rather than poping and freeing all of the existing entries so we can
reuse it. While here rename some arguments and variables.
ok inoguchi@ tb@
| -rw-r--r-- | src/lib/libcrypto/ct/ct_oct.c | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/src/lib/libcrypto/ct/ct_oct.c b/src/lib/libcrypto/ct/ct_oct.c index 3dae7d8456..94e67c6bc3 100644 --- a/src/lib/libcrypto/ct/ct_oct.c +++ b/src/lib/libcrypto/ct/ct_oct.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ct_oct.c,v 1.7 2021/12/20 17:19:19 jsing Exp $ */ | 1 | /* $OpenBSD: ct_oct.c,v 1.8 2021/12/20 17:23:07 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Written by Rob Stradling (rob@comodo.com) and Stephen Henson | 3 | * Written by Rob Stradling (rob@comodo.com) and Stephen Henson |
| 4 | * (steve@openssl.org) for the OpenSSL project 2014. | 4 | * (steve@openssl.org) for the OpenSSL project 2014. |
| @@ -316,10 +316,10 @@ i2o_SCT(const SCT *sct, unsigned char **out) | |||
| 316 | } | 316 | } |
| 317 | 317 | ||
| 318 | STACK_OF(SCT) * | 318 | STACK_OF(SCT) * |
| 319 | o2i_SCT_LIST(STACK_OF(SCT) **scts, const unsigned char **pp, size_t len) | 319 | o2i_SCT_LIST(STACK_OF(SCT) **out_scts, const unsigned char **pp, size_t len) |
| 320 | { | 320 | { |
| 321 | CBS cbs, cbs_scts, cbs_sct; | 321 | CBS cbs, cbs_scts, cbs_sct; |
| 322 | STACK_OF(SCT) *sk = NULL; | 322 | STACK_OF(SCT) *scts = NULL; |
| 323 | 323 | ||
| 324 | CBS_init(&cbs, *pp, len); | 324 | CBS_init(&cbs, *pp, len); |
| 325 | 325 | ||
| @@ -330,18 +330,14 @@ o2i_SCT_LIST(STACK_OF(SCT) **scts, const unsigned char **pp, size_t len) | |||
| 330 | if (CBS_len(&cbs) != 0) | 330 | if (CBS_len(&cbs) != 0) |
| 331 | goto err_invalid; | 331 | goto err_invalid; |
| 332 | 332 | ||
| 333 | if (scts == NULL || *scts == NULL) { | 333 | if (out_scts != NULL) { |
| 334 | if ((sk = sk_SCT_new_null()) == NULL) | 334 | SCT_LIST_free(*out_scts); |
| 335 | return NULL; | 335 | *out_scts = NULL; |
| 336 | } else { | ||
| 337 | SCT *sct; | ||
| 338 | |||
| 339 | /* Use the given stack, but empty it first. */ | ||
| 340 | sk = *scts; | ||
| 341 | while ((sct = sk_SCT_pop(sk)) != NULL) | ||
| 342 | SCT_free(sct); | ||
| 343 | } | 336 | } |
| 344 | 337 | ||
| 338 | if ((scts = sk_SCT_new_null()) == NULL) | ||
| 339 | return NULL; | ||
| 340 | |||
| 345 | while (CBS_len(&cbs_scts) > 0) { | 341 | while (CBS_len(&cbs_scts) > 0) { |
| 346 | SCT *sct; | 342 | SCT *sct; |
| 347 | 343 | ||
| @@ -350,24 +346,23 @@ o2i_SCT_LIST(STACK_OF(SCT) **scts, const unsigned char **pp, size_t len) | |||
| 350 | 346 | ||
| 351 | if (!o2i_SCT_internal(&sct, &cbs_sct)) | 347 | if (!o2i_SCT_internal(&sct, &cbs_sct)) |
| 352 | goto err; | 348 | goto err; |
| 353 | if (!sk_SCT_push(sk, sct)) { | 349 | if (!sk_SCT_push(scts, sct)) { |
| 354 | SCT_free(sct); | 350 | SCT_free(sct); |
| 355 | goto err; | 351 | goto err; |
| 356 | } | 352 | } |
| 357 | } | 353 | } |
| 358 | 354 | ||
| 359 | if (scts != NULL && *scts == NULL) | 355 | if (out_scts != NULL) |
| 360 | *scts = sk; | 356 | *out_scts = scts; |
| 361 | 357 | ||
| 362 | *pp = CBS_data(&cbs); | 358 | *pp = CBS_data(&cbs); |
| 363 | 359 | ||
| 364 | return sk; | 360 | return scts; |
| 365 | 361 | ||
| 366 | err_invalid: | 362 | err_invalid: |
| 367 | CTerror(CT_R_SCT_LIST_INVALID); | 363 | CTerror(CT_R_SCT_LIST_INVALID); |
| 368 | err: | 364 | err: |
| 369 | if (scts == NULL || *scts == NULL) | 365 | SCT_LIST_free(scts); |
| 370 | SCT_LIST_free(sk); | ||
| 371 | 366 | ||
| 372 | return NULL; | 367 | return NULL; |
| 373 | } | 368 | } |
