Repository navigation
Fix double fclose in wolfSSL_BIO_read_filename() - #11923
julek-wolfssl wants to merge 1 commit into
Conversation
wolfSSL_BIO_read_filename() closed the BIO's file even when the BIO did not own it, and kept the closed FILE* when the new file failed to open. wolfSSL_BIO_free() then closed it a second time. Close the old file only with BIO_CLOSE and always drop it from the BIO. wolfSSL_X509_load_crl_file() called wolfSSL_BIO_read_filename() twice on the same file, a leftover from a merge. Remove the second call. It opened the file twice and hit the double fclose when the second open failed. Fixes wolfSSL#11903
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the file-ownership and cleanup fix.
No open issues 🎉
What changed in this PR
Fixes #11903 by correcting file ownership and cleanup in wolfSSL_BIO_read_filename(), preventing a double close when opening a replacement file fails.
Changes:
- Close the previous file only when the BIO owns it, and clear the stored file handle.
- Remove the duplicate file-open call during CRL loading.
- Add regression tests for failed opens, recovery, and
BIO_NOCLOSEbehavior.
| File | Description |
|---|---|
tests/api/test_ossl_bio.h |
Declares and registers the new regression test. |
tests/api/test_ossl_bio.c |
Tests replacement-file failures and file ownership handling. |
src/x509.c |
Removes the redundant file-open call during CRL loading. |
src/bio.c |
Fixes file ownership checks, clears stale handles, and corrects the debug label. |
Review effort: Balanced
|
|
Thanks Juliusz! I tested f2c1b8f with the reproducer from #11903 ( |
wolfSSL_BIO_read_filename() closed the BIO's existing file even when the BIO did not own it. It also kept the closed FILE* in the BIO when the new file failed to open, so wolfSSL_BIO_free() closed it a second time.
Fixes #11903