HACKERONE

curl: Stack Buffer Overflow in cURL wolfSSL Backend (lib/vtls/wolfssl.c)_H1:3459636

Description

**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.
Visit Original Source

Basic Information

ID H1:3459636
Published Dec 9, 2025 at 18:59
Modified Dec 9, 2025 at 23:08

💭 Join the Security Discussion

🔒 Your email address will not be published. Required fields are marked *

⚠️ Please be respectful and constructive in your comments. Security discussions should remain professional.