Stack Buffer Overflow in cURL wolfSSL Backend (lib/vtls/wolfssl.c)
The wssl_strerror function in cURL's wolfSSL backend uses an unchecked strcpy into a caller-supplied buffer, relying on a DEBUGASSERT compiled out in release builds. With a buffer of 40 bytes or less, this causes a stack buffer overflow, potentially leading to a crash or code execution.
- Disclosed after 4 hours
Summary:
A stack-based buffer overflow exists in the wssl_strerror function of cURL's wolfSSL TLS backend. The function uses an unsafe strcpy call, relying solely on a DEBUGASSERT macro for boundary checking. This macro is disabled in production release builds (-DNDEBUG), allowing memory corruption when the function is called with a buffer size parameter of 40 bytes or less.
Affected Component:
File: lib/vtls/wolfssl.c
Function: wssl_strerror (lines 1542-1556)
Vulnerable Code: Line 1552: strcpy(buf, msg);
Proof of Concept: The vulnerability is confirmed by compiling and executing the following test program, which simulates the function in a release build context:
Create the test file poc.c:
#include <stdio.h>
#include <string.h>
// Simulates wssl_strerror in a RELEASE build (DEBUGASSERT is a no-op)
static char *wssl_strerror(unsigned long error, char *buf, unsigned long size) {
*buf = '\0';
// Simulate wolfSSL_ERR_error_string_n writing nothing to the buffer
if(!*buf) {
const char *msg = error ? "Unknown error" : "No error";
strcpy(buf, msg); // VULNERABLE CALL: ignores size
}
return buf;
}
int main() {
// This buffer is too small for "Unknown error" + null terminator (needs 13 bytes)
char small_buffer[12];
wssl_strerror(1, small_buffer, 12); // This will overflow
printf("Result: %s\n", small_buffer);
return 0;
}
Compile with AddressSanitizer to detect memory corruption:
gcc -fsanitize=address -g -o poc poc.c
Execute the program to trigger the overflow:
./poc
Observed Result: The program terminates due to a stack-buffer-overflow detected by AddressSanitizer. The diagnostic output shows a 14-byte write overflowing a 12-byte stack buffer, with the trace leading directly to the strcpy call inside wssl_strerror.
Impact
Summary:
This buffer overflow corrupts adjacent stack memory. As the wssl_strerror function is part of cURL's TLS error handling path, which processes data influenced by external network communication, this vulnerability could potentially lead to:
Denial of Service: Application crash.
Arbitrary Code Execution: Under specific conditions, an attacker could exploit the memory corruption to hijack control flow.
The severity is heightened because libcurl is a ubiquitous library embedded in countless applications and devices.
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 copies a fixed error string with strcpy and only checks the destination size via a DEBUGASSERT that is removed in release builds.
Impact
This could cause a denial of service (application crash) and, under specific conditions, arbitrary code execution.
What the attacker needed
Release build without DEBUGASSERT; buffer size of 40 bytes or less
How it was found
- Create a test program that simulates wssl_strerror in a release build.
- Compile the program with AddressSanitizer enabled.
- Run the program to trigger the 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.
A buffer is a fixed-size space in memory. The code copies an error message into that space without checking whether it fits, so a longer message spills over into nearby memory. This can crash the program or, in rare cases, let an attacker run their own code.
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.