-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a regress test exercising BIO_dup_chain() and triggering the leak
fixed in bio_lib.c r1.47 as confirmed by ASAN.
- Loading branch information
tb
committed
Aug 7, 2023
1 parent
3592d78
commit 1c25761
Showing
1 changed file
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: bio_chain.c,v 1.15 2023/03/04 12:13:11 tb Exp $ */ | ||
/* $OpenBSD: bio_chain.c,v 1.16 2023/08/07 11:00:54 tb Exp $ */ | ||
/* | ||
* Copyright (c) 2022 Theo Buehler <[email protected]> | ||
* | ||
|
@@ -460,6 +460,47 @@ bio_set_next_link_test(void) | |
return link_chains(use_bio_push); | ||
} | ||
|
||
static long | ||
dup_leak_cb(BIO *bio, int cmd, const char *argp, int argi, long argl, long ret) | ||
{ | ||
if (argi == BIO_CTRL_DUP) | ||
return 0; | ||
|
||
return ret; | ||
} | ||
|
||
static int | ||
bio_dup_chain_leak(void) | ||
{ | ||
BIO *bio[CHAIN_POP_LEN]; | ||
BIO *dup; | ||
int failed = 1; | ||
|
||
if (!bio_chain_create(BIO_s_null(), bio, nitems(bio))) | ||
goto err; | ||
|
||
if ((dup = BIO_dup_chain(bio[0])) == NULL) { | ||
fprintf(stderr, "BIO_set_callback() failed\n"); | ||
goto err; | ||
} | ||
|
||
BIO_set_callback(bio[CHAIN_POP_LEN - 1], dup_leak_cb); | ||
|
||
BIO_free_all(dup); | ||
if ((dup = BIO_dup_chain(bio[0])) != NULL) { | ||
fprintf(stderr, "BIO_dup_chain() succeeded unexpectedly\n"); | ||
BIO_free_all(dup); | ||
goto err; | ||
} | ||
|
||
failed = 0; | ||
|
||
err: | ||
bio_chain_destroy(bio, nitems(bio)); | ||
|
||
return failed; | ||
} | ||
|
||
int | ||
main(int argc, char **argv) | ||
{ | ||
|
@@ -468,6 +509,7 @@ main(int argc, char **argv) | |
failed |= bio_chain_pop_test(); | ||
failed |= bio_push_link_test(); | ||
failed |= bio_set_next_link_test(); | ||
failed |= bio_dup_chain_leak(); | ||
|
||
return failed; | ||
} |