diff options
author | tb <> | 2023-08-07 11:00:54 +0000 |
---|---|---|
committer | tb <> | 2023-08-07 11:00:54 +0000 |
commit | 351d4291287245bceea3615c001afa751242cb1e (patch) | |
tree | 5cefaed1416dfce9548305ca985229d4d3267bbc | |
parent | 6ebe6a57ddcecac61efec3fa67cdf37275e8dc2a (diff) | |
download | openbsd-351d4291287245bceea3615c001afa751242cb1e.tar.gz openbsd-351d4291287245bceea3615c001afa751242cb1e.tar.bz2 openbsd-351d4291287245bceea3615c001afa751242cb1e.zip |
Add a regress test exercising BIO_dup_chain() and triggering the leak
fixed in bio_lib.c r1.47 as confirmed by ASAN.
-rw-r--r-- | src/regress/lib/libcrypto/bio/bio_chain.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/bio/bio_chain.c b/src/regress/lib/libcrypto/bio/bio_chain.c index 9ab753f662..abf475bc4a 100644 --- a/src/regress/lib/libcrypto/bio/bio_chain.c +++ b/src/regress/lib/libcrypto/bio/bio_chain.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bio_chain.c,v 1.15 2023/03/04 12:13:11 tb Exp $ */ | 1 | /* $OpenBSD: bio_chain.c,v 1.16 2023/08/07 11:00:54 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> | 3 | * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> |
4 | * | 4 | * |
@@ -460,6 +460,47 @@ bio_set_next_link_test(void) | |||
460 | return link_chains(use_bio_push); | 460 | return link_chains(use_bio_push); |
461 | } | 461 | } |
462 | 462 | ||
463 | static long | ||
464 | dup_leak_cb(BIO *bio, int cmd, const char *argp, int argi, long argl, long ret) | ||
465 | { | ||
466 | if (argi == BIO_CTRL_DUP) | ||
467 | return 0; | ||
468 | |||
469 | return ret; | ||
470 | } | ||
471 | |||
472 | static int | ||
473 | bio_dup_chain_leak(void) | ||
474 | { | ||
475 | BIO *bio[CHAIN_POP_LEN]; | ||
476 | BIO *dup; | ||
477 | int failed = 1; | ||
478 | |||
479 | if (!bio_chain_create(BIO_s_null(), bio, nitems(bio))) | ||
480 | goto err; | ||
481 | |||
482 | if ((dup = BIO_dup_chain(bio[0])) == NULL) { | ||
483 | fprintf(stderr, "BIO_set_callback() failed\n"); | ||
484 | goto err; | ||
485 | } | ||
486 | |||
487 | BIO_set_callback(bio[CHAIN_POP_LEN - 1], dup_leak_cb); | ||
488 | |||
489 | BIO_free_all(dup); | ||
490 | if ((dup = BIO_dup_chain(bio[0])) != NULL) { | ||
491 | fprintf(stderr, "BIO_dup_chain() succeeded unexpectedly\n"); | ||
492 | BIO_free_all(dup); | ||
493 | goto err; | ||
494 | } | ||
495 | |||
496 | failed = 0; | ||
497 | |||
498 | err: | ||
499 | bio_chain_destroy(bio, nitems(bio)); | ||
500 | |||
501 | return failed; | ||
502 | } | ||
503 | |||
463 | int | 504 | int |
464 | main(int argc, char **argv) | 505 | main(int argc, char **argv) |
465 | { | 506 | { |
@@ -468,6 +509,7 @@ main(int argc, char **argv) | |||
468 | failed |= bio_chain_pop_test(); | 509 | failed |= bio_chain_pop_test(); |
469 | failed |= bio_push_link_test(); | 510 | failed |= bio_push_link_test(); |
470 | failed |= bio_set_next_link_test(); | 511 | failed |= bio_set_next_link_test(); |
512 | failed |= bio_dup_chain_leak(); | ||
471 | 513 | ||
472 | return failed; | 514 | return failed; |
473 | } | 515 | } |