Integer overflows in unescape_word()
The unescape_word() function in libcurl's DICT protocol handling multiplies the input length by two without checking for integer overflow, which on a 32-bit system could cause a heap buffer overflow when the input exceeds 2GB. An attacker could potentially trigger a crash or other impact by supplying an extremely long URL to a program using libcurl.
- Disclosed after 30 days
Summary:
A similiar issue to CVE-2019-5435
Steps To Reproduce:
analysis
DICT protocol can use one url like "dict://localhost:3306", and function unescape_word() is used to deal with the character in url like this comment
/* According to RFC2229 section 2.2, these letters need to be escaped with
\[letter] */
if((ch <= 32) || (ch == 127) ||
(ch == '\'') || (ch == '\"') || (ch == '\\')) {
dictp[olen++] = '\\';
}
and the bug case here /curl/lib/dict.c
static char *unescape_word(const char *inputbuff)
{
char *newp = NULL;
char *dictp;
size_t len;
CURLcode result = Curl_urldecode(inputbuff, 0, &newp, &len, <------------- get len
REJECT_NADA);
if(!newp || result)
return NULL;
dictp = malloc(len*2 + 1); <------------ overflow here
//.....
}
In my analysis(maybe wrong), the inputbuff in DICT url is "dict:[inputbuff]", for example "//localhost:3306" in "dict://localhost:3306", and len is the length of inputbuff.
And the length of inputbuff multiplied by 2 and then passed to malloc. This may lead to a integer overflow on a 32bit OS when the inputbuff is longer than 2GB
unescape_word was called by dict_do(), If someone use libcurl to code, and call dict_do() with a extreme long url, it might be triggered.
Impact
It might leads to a crash or some other impact.
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 length of the decoded input is multiplied by two without checking for overflow before being passed to malloc, so a very large input can cause a small allocation followed by a buffer overflow.
Impact
It might lead to a crash or some other impact, but only on a 32-bit OS and with an input longer than 2GB.
What the attacker needed
32-bit OS; input longer than 2GB; program uses libcurl and calls dict_do()
How it was found
- Use libcurl to call dict_do() with an extremely long URL.
- The URL is passed to unescape_word(), which decodes it and obtains its length.
- The length is multiplied by two and passed to malloc without overflow checking.
- On a 32-bit system, an input longer than 2GB causes an integer overflow, leading to a small allocation and subsequent buffer overflow.
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 a program needs to store a copy of some text, it calculates how much memory to reserve by multiplying the text length by a number. If the text is extremely long, that multiplication can wrap around to a small number, so the program reserves too little memory and then writes past the end of it. This is called an integer overflow and can crash the program.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.