Skip to content

Commit 1c25761

Browse files
author
tb
committed
Add a regress test exercising BIO_dup_chain() and triggering the leak
fixed in bio_lib.c r1.47 as confirmed by ASAN.
1 parent 3592d78 commit 1c25761

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

src/regress/lib/libcrypto/bio/bio_chain.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 $ */
22
/*
33
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
44
*
@@ -460,6 +460,47 @@ bio_set_next_link_test(void)
460460
return link_chains(use_bio_push);
461461
}
462462

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+
463504
int
464505
main(int argc, char **argv)
465506
{
@@ -468,6 +509,7 @@ main(int argc, char **argv)
468509
failed |= bio_chain_pop_test();
469510
failed |= bio_push_link_test();
470511
failed |= bio_set_next_link_test();
512+
failed |= bio_dup_chain_leak();
471513

472514
return failed;
473515
}

0 commit comments

Comments
 (0)