NULL dereference when encoding DN of x509 certificate
A NULL pointer dereference in libcurl's encodeDN() function occurs when a server presents a TLS certificate with a constructed OID, causing ASN1tostr to leave the temporary buffer empty. An attacker can crash any application using libcurl for TLS connections by serving such a certificate.
- Disclosed after 11 hours
libcurl at commit 04739054cdac5a0614fb94e3655e313c03399f35 contains a NULL-dereference in function encodeDN() when parsing the certificate of a server during the TLS connect-phase.
The vulnerable code is in lib/vtls/x509asn1.c:701:
static CURLcode encodeDN(struct dynbuf *store, struct Curl_asn1Element *dn)
{
struct dynbuf temp;
Curl_dyn_init(&temp, MAX_X509_STR);
for(p1 = dn->beg; p1 < dn->end;) {
for(p2 = rdn.beg; p2 < rdn.end;) {
// --- snip ---
Curl_dyn_reset(&temp);
result = ASN1tostr(&temp, &oid, 0);
if(result)
goto error;
str = Curl_dyn_ptr(&temp);
/* Encode delimiter.
If attribute has a short uppercase name, delimiter is ", ". */
for(p3 = str; ISUPPER(*p3); p3++)
;
}
}
}
When the oid that ASN1tostr tries to convert to a string is an element that is constructed such that oid.constructed is 1
ASN1tostr returns without touching the dynbuf temp. The following Curl_dyn_ptr() returns NULL and ISUPPER(*p3) causes
the application to crash.
Exploit scenario
The following exploit scenario demonstrates how to terminate an application using libcurl with the NULL dereference from above:
- Setup a malicious server with a TLS certificate that triggers the crash
- When a client connects over TLS, send the invalid certificate. This causes the client to terminate and no longer serve its purpose
Impact
The null dereference causes a DOS on applications using libcurl to do TLS-encrypted connections. It requires no special setup to trigger the crash, since it is triggered during the connect-phase of the connection. Thus I chose severity "Low".
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the code assumes ASN1tostr always writes to the temporary buffer, but for a constructed OID it returns early without doing so, leaving Curl_dyn_ptr returning NULL which is then dereferenced.
Impact
The null dereference causes a denial of service on applications using libcurl for TLS-encrypted connections, and it requires no special setup to trigger since it happens during the connect phase.
What the attacker needed
Malicious TLS server; client uses libcurl for TLS
How it was found
- Set up a malicious server with a TLS certificate that triggers the crash
- When a client connects over TLS, send the invalid certificate
- The client terminates and no longer serves its purpose
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When libcurl connects to a secure server, it reads the server's certificate and tries to turn some of its fields into text. If a field is malformed in a specific way, the text buffer stays empty and the program tries to read from an empty pointer, which crashes it. This means a malicious server can knock over any program that uses libcurl to make secure connections.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.