diff options
-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 | } |