libevent (stack) buffer overflow in evutil_parse_sockaddr_port
A length calculation in libevent's address parser casts a pointer difference to a signed 32-bit integer, so an extremely long bracketed address can wrap to a negative value and pass the bounds check. This leads to a stack buffer overflow and a crash when the copy is performed.
- Triaged in 3 days
- Fixed in 11 days
- Paid in 40 hours
- Disclosed after 21 months
in evutil.c:
1798 char buf[128];
...
...
1809 cp = strchr(ip_as_string, ':');
1810 if (*ip_as_string == '[') {
1811 int len;
1812 if (!(cp = strchr(ip_as_string, ']'))) {
1813 return -1;
1814 }
1815 len = (int) ( cp-(ip_as_string + 1) );
1816 if (len > (int)sizeof(buf)-1) {
1817 return -1;
1818 }
1819 memcpy(buf, ip_as_string+1, len);
Length between '[' and ']' is cast to signed 32 bit integer on line 1815. Is the length is more than 2<<31 (INT_MAX), len will hold a negative value. Consequently, it will pass the check at line 1816. Segfault happens at line 1819.
Generate a resolv.conf with generate-resolv.conf, then compile and run poc.c. See entry-functions.txt for functions in tor that might be vulnerable.
Guido
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 pointer difference is cast to a signed int before the size check, so an oversized length becomes negative and bypasses the comparison against the buffer size.
Impact
An attacker who can supply the parsed address string could trigger a stack buffer overflow and crash the program.
What the attacker needed
Attacker controls the parsed address string; address longer than 2^31 characters
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.
The code measures how long a piece of text is and stores that number in a type that cannot hold very large values. If the text is huge, the number wraps around and becomes negative, so a safety check that rejects numbers that are too big lets it through. The program then copies far too much text into a small fixed-size space on the stack, which corrupts memory and crashes it.
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.