Repository navigation
Conversation
do_pubkey_field() only freed its dynbuf when ASN1tostr() succeeded. utf8asn1str() appends one character at a time and bails out with CURLE_WEIRD_SERVER_REPLY on a 4 byte code point of 0x200000 or more, so a public key element encoded as a UniversalString with a bad character after some good ones leaked everything stored so far, up to the 100000 byte field limit, once per certinfo extraction. The server picks that encoding, and with GnuTLS the extraction runs before verification. Regression from 623c3a8 (8.6.0), the malloc based code freed the buffer on that path. Add a cert with such a key to test 1651.
|
Analysis of PR #23459 at 7af45af8: Test ../../tests/http/test_60_h3_proxy.py::TestH3Proxy::test_60_12_quic_session_resumption failed, but it has been permanently failing lately, so it's probably NOT a fault of the PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them). Note that this CI job has had a number of other flaky tests recently (4, to be specific) so it may be that this failure is rather a systemic issue with this job and not with this specific PR. Generated by Testclutch |
There was a problem hiding this comment.
🟢 Approval recommended
The localized cleanup fixes the leak while preserving existing behavior, and the regression case targets the failure path.
No open issues 🎉
What changed in this PR
Fixes a memory leak during certificate-info extraction when public-key field conversion fails.
Changes:
- Frees the field buffer on both successful and failed conversions.
- Adds a malformed-certificate regression case targeting partial conversion failure.
| File | Description |
|---|---|
| tests/unit/unit1651.c | Adds a certificate fixture that triggers conversion failure after buffering data. |
| lib/vtls/x509asn1.c | Makes public-key field buffer cleanup unconditional. |
Review effort: Balanced
|
Thanks! |
do_pubkey_field() frees its dynbuf only when ASN1tostr() succeeds, but utf8asn1str() appends one character at a time and bails with CURLE_WEIRD_SERVER_REPLY on a 4 byte code point of 0x200000 or more, so a chain cert whose public key element is a UniversalString with a bad character after some good ones leaks everything stored so far, up to the 100000 byte field cap, on every certinfo extraction. i found it on a GnuTLS build with CURLOPT_CERTINFO (the tool sets that for any -w): ASAN reports a 100016 byte direct leak from dyn_nappend < ASN1tostr < do_pubkey_field < Curl_extract_certinfo < Curl_gtls_verifyserver, which runs before verification so the chain does not even have to validate. Regression from 623c3a8 (8.6.0), the malloc based code freed the buffer on that path. The cert added to test 1651 makes the test fail without the fix and pass with it, checked on 8.23.0 with GnuTLS.