curl / curl

A command line tool and library for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, TFTP, WS and WSS. libcurl offers a myriad of powerful features
https://curl.se/
Other
34.74k stars 6.24k forks source link

More NULL dereferences in x509asn1.c #13978

Closed z2-2z closed 1 week ago

z2-2z commented 1 week ago

Hello,

in #13972 you fixed a possible NULL dereference in the ASN1tostr() function. The root cause was that when converting a Curl_asn1Element with length = 0 to a string, the dynbuf temp in ASN1tostr() does not get initialized through one path of the ASN1tostr() function such that Curl_dyn_ptr(&temp) then returns NULL.

Unfortunately there are at least 4 more paths through ASN1tostr() and its helper functions that lead to the same outcome, involving the functions:

This PR tries to fix the NULL derefs in one place instead of all the helper functions above.

For reference, I attached all 4 certificates that cause a NULL dereference: crash-ecf257c87027696ed7f041bb764e0028adb95408 crash-26e2227eeeac47626b14bedfa6793b7c85223fca crash-da35663a566f4c1ccd929bb658b64e2ab925cd07 crash-fddfc08fd1b21a188f99692c8aaf85fdc560ef5d

bagder commented 1 week ago

Thanks!