Skip to content
Memory corruption Disclosed report Advanced

## Title Heap Use-After-Free Vulnerability in `curl` Leading to Potential Code Execution

A heap use-after-free was found in curl's error-buffer handling, where a freed buffer may be written to via strcpy. An attacker who can influence the input could crash the process and possibly leak memory or execute code.

irene1hacker Follow

Originally disclosed on HackerOne

  • Disclosed after 16 hours

Summary

A Use-After-Free (UAF) vulnerability was discovered in curl at curl_trc.c:195.
When processing specially crafted input, the code accesses memory after it has already been freed.
This can result in undefined behavior, leading to a denial of service (crash) and potentially enabling information disclosure or remote code execution, depending on the attacker’s ability to control heap layout.

code

C
if(data->set.errorbuffer && !data->state.errorbuf) {
   strcpy(data->set.errorbuffer, error); 
   data->state.errorbuf = TRUE; /* wrote error string */ 
}

Affected version

curl 8.16.0-DEV (Linux) libcurl/8.16.0-DEV

Steps To Reproduce:

I used LLVM libFuzzer to find this.

1.Compile libcurl with sanitizers enabled:

Shell
mkdir build && cd build
CC=clang CXX=clang++ cmake ..   -DCMAKE_BUILD_TYPE=Debug   -DCMAKE_C_FLAGS="-g -O1 -fsanitize=address"   -DBUILD_SHARED_LIBS=OFF   -DBUILD_STATIC_LIBS=ON   -DBUILD_TESTING=OFF   -DBUILD_EXAMPLES=OFF   -DENABLE_MANUAL=OFF
cmake --build . --config Debug
  1. Build the fuzz target vulnerablityfuzz.cpp with coverage instrumentation enabled.
Shell
clang++ -g -O1 -fsanitize=address,fuzzer   -I../include   -I../src/include   vulnerablityfuzz.cpp ./lib/libcurl-d.a -o vulfuzz   -lpsl -ldl -lpthread -lssl -lcrypto -lz
  1. Run the fuzzer:
Shell
./vulfuzz

Supporting Material/References:

image.png
image.png From the original on HackerOne

(Attachment on the original report: curl_vulnerability_fuzzer.cpp)

Impact

Summary:

The discovered vulnerability is a heap-use-after-free in curl that occurs when previously freed heap memory is accessed and written via strcpy().

An attacker who can influence the input processed by the vulnerable functions (e.g., SSL configuration, proxy configuration, or callback functions) may achieve the following impacts:

  • Denial of Service (DoS):
    By triggering the use-after-free condition, an attacker can reliably crash the process, making the application or service unavailable.

  • Information Disclosure:
    Since freed memory may still contain sensitive data, an attacker may be able to read unintended memory contents, potentially leaking secrets such as credentials or session tokens.

  • Arbitrary Code Execution (High Risk):
    With careful heap grooming, an attacker could exploit the dangling pointer to overwrite adjacent memory structures, potentially gaining control of program flow and executing arbitrary code in the context of the application.

Given that curl is widely used in network-related applications, exploitation of this bug can have a significant impact on the security of systems that rely on it.

The original report as published on HackerOne, by irene1hacker. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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 error-buffer pointer in the transfer state is not cleared or invalidated when the buffer is freed, so a later error path writes through the dangling pointer.

Impact

The bug can reliably crash the process, and the report claims it may also leak freed memory contents or, with heap grooming, lead to code execution.

What the attacker needed

Attacker can influence curl input; ability to control heap layout (for RCE)

How it was found

  1. Compile libcurl with AddressSanitizer and debug flags.
  2. Build a libFuzzer target linked against the static libcurl.
  3. Run the fuzzer to trigger the use-after-free.

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 use-after-free happens when a program keeps a pointer to memory it has already released and then reads or writes through that pointer. Here curl writes an error message into a buffer that may already have been freed, so the program can crash or, in the worst case, an attacker can influence what happens next.

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.

More by irene1hacker

View all

1 more disclosed report, best first.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.