Repository navigation
Free certificates, not just the list, in the OpenSSL credentials code - #233
Open
xu826Jamin wants to merge 1 commit into
Open
xu826Jamin wants to merge 1 commit into
xu826Jamin wants to merge 1 commit into
Conversation
…code openssl_load_x509() returns a STACK_OF(X509) that owns the certificates it read, but five callers released it with sk_X509_free(), which frees only the list and leaks every certificate in it. Use sk_X509_pop_free(list, X509_free) in cupsAreCredentialsValidForName, cupsGetCredentialsExpiration, cupsGetCredentialsInfo and the two lists in cupsGetCredentialsTrust. "./testcreds" in an AddressSanitizer build leaked 313,791 bytes in 5,939 allocations before the change; this change removes most of that (41,818 bytes in 680 allocations remain, from other functions).
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sk_X509_free()frees only the list, not the certificates in it. Five callers incups/tls-openssl.crelease a list returned byopenssl_load_x509()(which owns its certificates) that way, so every certificate leaks. This changes them tosk_X509_pop_free(list, X509_free):cupsAreCredentialsValidForNamecupsGetCredentialsExpirationcupsGetCredentialsInfocupsGetCredentialsTrust(thesitecertslist and thecertslist;certis taken off the list withsk_X509_shift()and is still freed separately)Five lines changed, one file.
How I found and checked it
Built master (dba4a4e) with
--with-sanitizer=address --enable-debugagainst OpenSSL 3.0.13 and ran./testcredsincups/(relinking the binary each time):The remaining 41,818 bytes come from other functions in the same file (extension stacks and public-key references in
cupsCreateCredentialsandcupsSignCredentialsRequest); I can send those as a separate change if you want them.testhttpalso passes. I did not test GnuTLS, LibreSSL or Valgrind.I deliberately did not touch
_httpFreeCredentials:_httpTLSStarthands the chain certificates to the SSL context, so freeing them there as well would double-free.AI assistance (per DEVELOPING.md)
Assisted-by: Claude:claude-sonnet-5-5 AddressSanitizer