Skip to content
Memory corruption Disclosed report Advanced

Stack use-after-scope in HTTP/3 POST request processing via CURLOPT_POSTFIELDS

The researcher reports that libcurl keeps a pointer to POST data supplied through CURLOPT_POSTFIELDS and later reads it after the caller's stack buffer has gone out of scope. In the demonstrated case this causes a crash detected by AddressSanitizer, which the author frames as a denial of service.

geeknik Follow

Originally disclosed on HackerOne

  • Disclosed after under an hour

Summary by the researcher

Audit every libcurl POST in your stack. Treat CURLOPT_POSTFIELDS like explosives. Either switch to CURLOPT_COPYPOSTFIELDS or prove your pointer lives forever. No exceptions.

The report

Summary

A stack use-after-scope vulnerability exists in libcurl's HTTP/3 request processing when using CURLOPT_POSTFIELDS with stack-allocated buffers. libcurl retains a pointer to user-provided POST data but accesses it after the original stack frame has been destroyed, leading to memory corruption and potential denial of service.

The vulnerability occurs in Curl_pretransfer() at transfer.c:569 when libcurl calls strlen() on the previously stored POST data pointer that now points to invalid stack memory.

Steps to Reproduce / Proof of Concept

Environment

  • libcurl version: 8.16.0-DEV (master branch)
  • Compiler: Clang 20.1.8 with AddressSanitizer
  • Platform: macOS (ARM64)
  • Configuration: HTTP/3 enabled with ngtcp2/nghttp3

Reproduction Steps

  1. Build libcurl with ASAN:
Bash
  export CC=clang
  export CFLAGS="-O1 -g -fsanitize=address,undefined"
  ./configure --with-openssl --with-nghttp2 --with-nghttp3 --with-ngtcp2
  make
  1. Compile the reproducer:
  // http3_crash_poc.c
  #include <curl/curl.h>
  #include <string.h>

  int main() {
      CURL *curl = curl_easy_init();

      // Stack-allocated buffer that goes out of scope
      {
          char body_data[257];
          memset(body_data, 'A', 256);
          body_data[256] = '\0';

          curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
          curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_3);
          curl_easy_setopt(curl, CURLOPT_POST, 1L);
          curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body_data); // Vulnerable call
          curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 50L);
      } // body_data goes out of scope here

      // libcurl accesses invalid memory during transfer
      curl_easy_perform(curl);
      curl_easy_cleanup(curl);
      return 0;
  }
  1. Compile and run:
Bash
  clang -fsanitize=address http3_crash_poc.c -lcurl -o poc
  ./poc

Crash Output

  ==3720==ERROR: AddressSanitizer: stack-use-after-scope on address 0x00016fa21470
  READ of size 45 at 0x00016fa21470 thread T0
      #0 strlen
      #1 Curl_pretransfer transfer.c:569
      #2 multi_runsingle multi.c:2376
      #3 curl_multi_perform multi.c:2756
      #4 easy_transfer easy.c:705
      #5 easy_perform easy.c:813

  SUMMARY: AddressSanitizer: stack-use-after-scope transfer.c:569 in Curl_pretransfer

Fuzzer Discovery

This vulnerability was discovered using a custom libFuzzer fuzzing harness.

Technical Analysis

Root Cause

The vulnerability stems from libcurl's CURLOPT_POSTFIELDS behavior:

  1. libcurl stores the pointer but doesn't copy the data
  2. The application's stack buffer becomes invalid after scope exit
  3. libcurl later dereferences the invalid pointer in Curl_pretransfer()

Affected Code Path

curl_easy_setopt(CURLOPT_POSTFIELDS) → curl_easy_perform() → Curl_pretransfer() → strlen(invalid_pointer) → CRASH

Recommended Fix

  1. Documentation: Clarify that CURLOPT_POSTFIELDS data must remain valid until transfer completion
  2. API Enhancement: Consider adding bounds checking or automatic copying for stack-detected pointers
  3. Alternative API: Promote CURLOPT_COPYPOSTFIELDS for safer usage patterns

Impact

Security Impact

  1. Denial of Service: Guaranteed crash leading to application termination
  2. Memory Corruption: Use-after-scope can lead to unpredictable behavior
  3. Potential Code Execution: In specific circumstances, memory corruption could be leveraged for control flow hijacking

Affected Scenarios

  • Applications using libcurl for HTTP/3 requests with POST data
  • Any code pattern where CURLOPT_POSTFIELDS points to stack-allocated memory
  • Particularly affects:
    • HTTP/3 client applications
    • API clients using stack buffers for request bodies
    • Embedded systems with limited heap usage

Real-World Exposure

  • Language bindings: Many curl bindings may inadvertently create this pattern
  • Example applications: CLI tools, web scrapers, API clients
  • Severity: High due to HTTP/3 adoption growth and remote exploitability

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

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

libcurl is the client-side transfer library behind curl. Applications configure a transfer by setting options on an easy handle with curl_easy_setopt(), then run it with curl_easy_perform(). One of those options, CURLOPT_POSTFIELDS, supplies the body of a POST request.

The behaviour that matters here is documented in the option's name: libcurl does not copy the data you pass. It keeps the pointer you gave it and reads from that memory later, when the transfer actually runs. If the buffer you pointed at is gone by then, libcurl is reading freed or out-of-scope memory.

The report describes a stack use-after-scope in libcurl's HTTP/3 request processing when CURLOPT_POSTFIELDS is given a stack-allocated buffer. The pointer is retained, the stack frame that owned the buffer is destroyed, and libcurl later dereferences the stale pointer. The researcher rates the severity high.

Setup

The researcher reproduced the issue on the following configuration:

Item Value
libcurl version 8.16.0-DEV (master branch)
Compiler Clang 20.1.8 with AddressSanitizer
Platform macOS (ARM64)
Configuration HTTP/3 enabled with ngtcp2/nghttp3

The vulnerability was found with a custom libFuzzer fuzzing harness, and the proof of concept below was built with AddressSanitizer.

Finding it

The pattern that looked wrong is the lifetime mismatch between the option and the transfer. CURLOPT_POSTFIELDS stores a pointer without copying the data, while curl_easy_perform() is what triggers the read. Any buffer whose lifetime ends between the curl_easy_setopt() call and the transfer is a candidate for a use-after-scope.

In the reproducer the buffer is a local array inside a nested block. The block closes before curl_easy_perform() is called, so the memory the handle still points at is no longer valid. Under AddressSanitizer the access is caught at the point where libcurl measures the POST body.

Exploitation

Step 1: build libcurl with ASAN

Bash
export CC=clang
export CFLAGS="-O1 -g -fsanitize=address,undefined"
./configure --with-openssl --with-nghttp2 --with-nghttp3 --with-ngtcp2
make

The build enables AddressSanitizer and UndefinedBehaviorSanitizer at -O1 with debug information, and configures libcurl with OpenSSL, nghttp2, nghttp3 and ngtcp2 so that HTTP/3 support is compiled in.

Step 2: compile the reproducer

Text
// http3_crash_poc.c
#include <curl/curl.h>
#include <string.h>

int main() {
    CURL *curl = curl_easy_init();

    // Stack-allocated buffer that goes out of scope
    {
        char body_data[257];
        memset(body_data, 'A', 256);
        body_data[256] = '\0';

        curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
        curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_3);
        curl_easy_setopt(curl, CURLOPT_POST, 1L);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body_data); // Vulnerable call
        curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 50L);
    } // body_data goes out of scope here

    // libcurl accesses invalid memory during transfer
    curl_easy_perform(curl);
    curl_easy_cleanup(curl);
    return 0;
}

The handle is configured for https://example.com/ over HTTP/3 with CURL_HTTP_VERSION_3, a POST is enabled, and the body is the 257-byte stack array body_data, filled with A and NUL-terminated. The CURLOPT_POSTFIELDS call is the vulnerable one: it hands libcurl a pointer into the block's stack frame. The block then closes, so body_data is out of scope before curl_easy_perform() runs. A 50 ms timeout is set with CURLOPT_TIMEOUT_MS.

Step 3: compile and run

Bash
clang -fsanitize=address http3_crash_poc.c -lcurl -o poc
./poc

Running the binary produces the following crash output:

Text
==3720==ERROR: AddressSanitizer: stack-use-after-scope on address 0x00016fa21470
READ of size 45 at 0x00016fa21470 thread T0
    #0 strlen
    #1 Curl_pretransfer transfer.c:569
    #2 multi_runsingle multi.c:2376
    #3 curl_multi_perform multi.c:2756
    #4 easy_transfer easy.c:705
    #5 easy_perform easy.c:813

SUMMARY: AddressSanitizer: stack-use-after-scope transfer.c:569 in Curl_pretransfer

AddressSanitizer reports a stack-use-after-scope read of 45 bytes at the stale address. The stack trace runs from strlen through Curl_pretransfer() at transfer.c:569, then through multi_runsingle() at multi.c:2376, curl_multi_perform() at multi.c:2756, easy_transfer() at easy.c:705 and easy_perform() at easy.c:813. The summary line names transfer.c:569 in Curl_pretransfer as the faulting location.

Root cause

The root cause is the lifetime contract of CURLOPT_POSTFIELDS, as the researcher lays it out:

  1. libcurl stores the pointer but does not copy the data.
  2. The application's stack buffer becomes invalid after scope exit.
  3. libcurl later dereferences the invalid pointer in Curl_pretransfer().

The affected code path is:

Text
curl_easy_setopt(CURLOPT_POSTFIELDS) →
curl_easy_perform() →
Curl_pretransfer() →
strlen(invalid_pointer) →
CRASH

The specific faulting operation is the strlen() call in Curl_pretransfer() at transfer.c:569, which measures the previously stored POST data pointer after the original stack frame has been destroyed. The result is memory corruption and potential denial of service.

Impact

The researcher lists three levels of security impact:

  1. Denial of service: a guaranteed crash leading to application termination.
  2. Memory corruption: use-after-scope can lead to unpredictable behaviour.
  3. Potential code execution: in specific circumstances, memory corruption could be leveraged for control flow hijacking.

The affected scenarios are applications using libcurl for HTTP/3 requests with POST data, and any code pattern where CURLOPT_POSTFIELDS points to stack-allocated memory. The researcher calls out HTTP/3 client applications, API clients using stack buffers for request bodies, and embedded systems with limited heap usage as particularly affected.

On real-world exposure, the report notes that many curl language bindings may inadvertently create this pattern, and that CLI tools, web scrapers and API clients are example applications. The report rates the severity high, citing HTTP/3 adoption growth and remote exploitability.

Fix

The researcher recommends three measures:

  1. Documentation: clarify that CURLOPT_POSTFIELDS data must remain valid until transfer completion.
  2. API enhancement: consider adding bounds checking or automatic copying for stack-detected pointers.
  3. Alternative API: promote CURLOPT_COPYPOSTFIELDS for safer usage patterns.

The researcher's own summary is blunt: audit every libcurl POST in your stack and treat CURLOPT_POSTFIELDS like explosives. Either switch to CURLOPT_COPYPOSTFIELDS or prove the pointer lives forever, with no exceptions.

Variants to test

  • Other transfer paths that read the POST body late. The crash here is in Curl_pretransfer() on the HTTP/3 path. Try the same out-of-scope buffer with other protocol backends and other request methods that carry a body. A positive result is an AddressSanitizer stack-use-after-scope report pointing at a libcurl frame that reads the stored pointer.
  • Language bindings that wrap CURLOPT_POSTFIELDS. Look for bindings that pass a temporary or stack-backed buffer to the option without copying. A positive result is a crash or ASAN report in the binding's POST path when the buffer's owner goes away before the transfer completes.
  • Longer-lived but still freed buffers. Instead of a stack array, free a heap buffer after curl_easy_setopt() and before curl_easy_perform(). A positive result is a heap-use-after-free report at the same strlen call in Curl_pretransfer().
  • Reuse of the same easy handle. Set CURLOPT_POSTFIELDS to a buffer, let it go out of scope, then perform more than one transfer on the handle. A positive result is the stale pointer being read on a later transfer, not only the first.
  • Timeout and cancellation paths. The reproducer sets CURLOPT_TIMEOUT_MS to 50. Vary the timing so the transfer is aborted or retried at different points. A positive result is the invalid pointer being dereferenced during cleanup or retry rather than during the initial pretransfer.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

A programmer wrote a small test program that uses a popular piece of software called libcurl to send data to a website. The program crashed, and a tool that watches for memory mistakes caught the exact reason. The crash happens because libcurl remembers where the data is instead of making its own copy, and by the time libcurl goes to read that data, the place it was stored no longer exists.

To follow this you only need a few ideas. A library is a bundle of ready-made code that other programs use so they do not have to write everything themselves. libcurl is a library for talking to servers over the internet: fetching pages, uploading files, sending forms. curl is the command-line program built on top of libcurl, and libcurl is what many applications embed. An API (application programming interface) is the set of instructions a library offers to the programs that use it, like a menu of functions you can call. When a program uses libcurl, it calls functions from that menu.

The report is about one specific menu item: CURLOPT_POSTFIELDS. A POST request is the kind of web request a browser sends when you submit a form, carrying a body of data to the server. CURLOPT_POSTFIELDS is the option that tells libcurl what that body is. The catch, which the report is built around, is that libcurl does not copy the body. It only remembers the address in memory where the body lives, and reads it later when the request actually goes out.

Memory addresses work a bit like a locker number. If you tell someone "my parcel is in locker 42" and then empty locker 42 and give it to someone else, the person who goes to locker 42 later will find the wrong thing, or nothing. That is the essence of this bug. The technical name for reading memory that is no longer valid is a use-after-free or, in the specific case here, a use-after-scope: the memory belonged to a short-lived part of the program and was reclaimed when that part finished.

The report describes this happening in libcurl's HTTP/3 request processing. HTTP/3 is a newer version of the protocol browsers and servers use to exchange web traffic. The researcher rates the severity high.

Context

libcurl is the client-side transfer library behind curl. Client-side means it runs on your machine and talks to a server, as opposed to server-side code that answers requests. Applications configure a transfer by setting options on an easy handle with curl_easy_setopt(), then run it with curl_easy_perform(). An easy handle is libcurl's internal object representing one transfer: you create it, adjust its settings, run it, and clean it up.

One of those options, CURLOPT_POSTFIELDS, supplies the body of a POST request. The behaviour that matters here is documented in the option's name: libcurl does not copy the data you pass. It keeps the pointer you gave it and reads from that memory later, when the transfer actually runs. A pointer is a number that says where in memory something is stored, like a street address rather than the house itself. If the buffer you pointed at is gone by then, libcurl is reading freed or out-of-scope memory.

The report describes a stack use-after-scope in libcurl's HTTP/3 request processing when CURLOPT_POSTFIELDS is given a stack-allocated buffer. The stack is a region of memory a program uses for short-lived local variables, the ones that exist only while a particular function or block is running. When that block ends, its stack space is considered free and can be reused. The pointer is retained, the stack frame that owned the buffer is destroyed, and libcurl later dereferences the stale pointer. Dereferencing means following a pointer to read or write the memory it points at. The researcher rates the severity high.

Setup

The researcher reproduced the issue on the following configuration:

Item Value
libcurl version 8.16.0-DEV (master branch)
Compiler Clang 20.1.8 with AddressSanitizer
Platform macOS (ARM64)
Configuration HTTP/3 enabled with ngtcp2/nghttp3

A compiler turns human-readable source code into a program the computer can run; Clang is one such compiler. AddressSanitizer (ASAN) is a debugging tool built into the compiler that adds checks around memory accesses, so that a bad read is reported loudly at the moment it happens instead of silently corrupting something. ARM64 is a family of processor used in Apple's newer Macs. ngtcp2 and nghttp3 are libraries that implement the transport and HTTP/3 layers libcurl needs to speak HTTP/3.

The vulnerability was found with a custom libFuzzer fuzzing harness. Fuzzing means feeding a program huge numbers of generated inputs to see which ones make it misbehave; libFuzzer is a tool that does this automatically. A harness is the small wrapper program that connects the fuzzer to the code under test. The proof of concept below was built with AddressSanitizer. A proof of concept (PoC) is a minimal program that demonstrates a bug actually happening.

Finding it

The pattern that looked wrong is the lifetime mismatch between the option and the transfer. Lifetime here means how long a piece of memory stays valid. CURLOPT_POSTFIELDS stores a pointer without copying the data, while curl_easy_perform() is what triggers the read. Any buffer whose lifetime ends between the curl_easy_setopt() call and the transfer is a candidate for a use-after-scope.

In the reproducer the buffer is a local array inside a nested block. The block closes before curl_easy_perform() is called, so the memory the handle still points at is no longer valid. Under AddressSanitizer the access is caught at the point where libcurl measures the POST body.

Exploitation

Step 1: build libcurl with ASAN

Bash
export CC=clang
export CFLAGS="-O1 -g -fsanitize=address,undefined"
./configure --with-openssl --with-nghttp2 --with-nghttp3 --with-ngtcp2
make

Line by line:

  1. export CC=clang tells the build system to use the Clang compiler rather than whatever it would pick by default.
  2. export CFLAGS="-O1 -g -fsanitize=address,undefined" sets the compiler flags. -O1 is a light optimisation level, -g keeps debug information so error reports can name source lines, -fsanitize=address turns on AddressSanitizer, and -fsanitize=undefined turns on UndefinedBehaviorSanitizer, which flags other kinds of invalid program behaviour.
  3. ./configure --with-openssl --with-nghttp2 --with-nghttp3 --with-ngtcp2 runs libcurl's configuration script, telling it to build with OpenSSL (for encryption), nghttp2 (HTTP/2), nghttp3 (HTTP/3) and ngtcp2 (the transport underneath HTTP/3).
  4. make actually compiles the library.

The build enables AddressSanitizer and UndefinedBehaviorSanitizer at -O1 with debug information, and configures libcurl with OpenSSL, nghttp2, nghttp3 and ngtcp2 so that HTTP/3 support is compiled in.

Step 2: compile the reproducer

Text
// http3_crash_poc.c
#include <curl/curl.h>
#include <string.h>

int main() {
    CURL *curl = curl_easy_init();

    // Stack-allocated buffer that goes out of scope
    {
        char body_data[257];
        memset(body_data, 'A', 256);
        body_data[256] = '\0';

        curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
        curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_3);
        curl_easy_setopt(curl, CURLOPT_POST, 1L);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body_data); // Vulnerable call
        curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 50L);
    } // body_data goes out of scope here

    // libcurl accesses invalid memory during transfer
    curl_easy_perform(curl);
    curl_easy_cleanup(curl);
    return 0;
}

Line by line:

  1. #include <curl/curl.h> and #include <string.h> pull in the declarations for libcurl and for the string helper functions used below.
  2. int main() { starts the program's entry point.
  3. CURL *curl = curl_easy_init(); creates a new easy handle and stores a pointer to it in curl.
  4. The opening { starts a nested block. Anything declared inside it lives only until the matching closing }.
  5. char body_data[257]; declares a local array of 257 characters on the stack. This is the buffer that will hold the POST body.
  6. memset(body_data, 'A', 256); fills the first 256 bytes with the letter A.
  7. body_data[256] = '\0'; puts a zero byte at the end. In C, strings are terminated by a zero byte, and functions like strlen rely on it to know where the string stops.
  8. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/"); sets the destination address.
  9. curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_3); asks libcurl to use HTTP/3.
  10. curl_easy_setopt(curl, CURLOPT_POST, 1L); switches the request method to POST.
  11. curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body_data); is the vulnerable call. It hands libcurl the address of body_data without copying the contents.
  12. curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 50L); sets a 50 millisecond timeout so the test does not hang.
  13. The closing } ends the block, so body_data goes out of scope and its stack space is no longer reserved for it.
  14. curl_easy_perform(curl); runs the transfer. This is where libcurl reads the body, using the now-stale pointer.
  15. curl_easy_cleanup(curl); frees the handle, and return 0; ends the program.

The handle is configured for https://example.com/ over HTTP/3 with CURL_HTTP_VERSION_3, a POST is enabled, and the body is the 257-byte stack array body_data, filled with A and NUL-terminated. The CURLOPT_POSTFIELDS call is the vulnerable one: it hands libcurl a pointer into the block's stack frame. The block then closes, so body_data is out of scope before curl_easy_perform() runs. A 50 ms timeout is set with CURLOPT_TIMEOUT_MS.

Step 3: compile and run

Bash
clang -fsanitize=address http3_crash_poc.c -lcurl -o poc
./poc
  1. clang -fsanitize=address http3_crash_poc.c -lcurl -o poc compiles the source file with AddressSanitizer enabled, links it against libcurl (-lcurl), and writes the resulting program to a file called poc.
  2. ./poc runs that program.

Running the binary produces the following crash output:

Text
==3720==ERROR: AddressSanitizer: stack-use-after-scope on address 0x00016fa21470
READ of size 45 at 0x00016fa21470 thread T0
    #0 strlen
    #1 Curl_pretransfer transfer.c:569
    #2 multi_runsingle multi.c:2376
    #3 curl_multi_perform multi.c:2756
    #4 easy_transfer easy.c:705
    #5 easy_perform easy.c:813

SUMMARY: AddressSanitizer: stack-use-after-scope transfer.c:569 in Curl_pretransfer

AddressSanitizer reports a stack-use-after-scope read of 45 bytes at the stale address. The stack trace runs from strlen through Curl_pretransfer() at transfer.c:569, then through multi_runsingle() at multi.c:2376, curl_multi_perform() at multi.c:2756, easy_transfer() at easy.c:705 and easy_perform() at easy.c:813. The summary line names transfer.c:569 in Curl_pretransfer as the faulting location.

A stack trace is the list of function calls that led to the problem, read from the innermost call outwards. strlen is the standard C function that measures how long a string is by counting characters until the zero byte. Curl_pretransfer is libcurl's internal function that prepares a transfer before it starts, and it is the one calling strlen on the stored body pointer. The lines below it show how the program got there: multi_runsingle, curl_multi_perform, easy_transfer and easy_perform are libcurl's internal layers that eventually run the transfer. The file and line numbers (transfer.c:569, multi.c:2376, and so on) point at the exact source locations.

Root cause

The root cause is the lifetime contract of CURLOPT_POSTFIELDS, as the researcher lays it out:

  1. libcurl stores the pointer but does not copy the data.
  2. The application's stack buffer becomes invalid after scope exit.
  3. libcurl later dereferences the invalid pointer in Curl_pretransfer().

The affected code path is:

Text
curl_easy_setopt(CURLOPT_POSTFIELDS) →
curl_easy_perform() →
Curl_pretransfer() →
strlen(invalid_pointer) →
CRASH

This is a chain: the program hands over the pointer, then asks libcurl to run the transfer, libcurl prepares the transfer, measures the body with strlen, and crashes because the memory it measures is no longer valid. The specific faulting operation is the strlen() call in Curl_pretransfer() at transfer.c:569, which measures the previously stored POST data pointer after the original stack frame has been destroyed. The result is memory corruption and potential denial of service. Memory corruption means memory is read or written in a way the program did not intend, which can make it behave unpredictably. Denial of service means the program stops working, so the service it provides is unavailable.

Impact

The researcher lists three levels of security impact:

  1. Denial of service: a guaranteed crash leading to application termination.
  2. Memory corruption: use-after-scope can lead to unpredictable behaviour.
  3. Potential code execution: in specific circumstances, memory corruption could be leveraged for control flow hijacking.

Code execution means an attacker gets their own instructions to run on the machine. Control flow hijacking means redirecting the program so it does something other than what it was written to do, for example jumping to attacker-chosen code.

The affected scenarios are applications using libcurl for HTTP/3 requests with POST data, and any code pattern where CURLOPT_POSTFIELDS points to stack-allocated memory. The researcher calls out HTTP/3 client applications, API clients using stack buffers for request bodies, and embedded systems with limited heap usage as particularly affected. Embedded systems are small computers built into devices, and heap is the other main region of memory, used for longer-lived allocations than the stack.

On real-world exposure, the report notes that many curl language bindings may inadvertently create this pattern. A language binding is a wrapper that lets programs written in another language, such as Python or Java, call into a C library like libcurl. The report also names CLI tools, web scrapers and API clients as example applications. CLI means command-line interface, a program you run by typing commands. The report rates the severity high, citing HTTP/3 adoption growth and remote exploitability. Remote exploitability means the bug can be triggered by someone who is not sitting at the machine, over a network.

Fix

The researcher recommends three measures:

  1. Documentation: clarify that CURLOPT_POSTFIELDS data must remain valid until transfer completion.
  2. API enhancement: consider adding bounds checking or automatic copying for stack-detected pointers.
  3. Alternative API: promote CURLOPT_COPYPOSTFIELDS for safer usage patterns.

CURLOPT_COPYPOSTFIELDS is the sibling option that does copy the data, so the caller's buffer can be freed or go out of scope safely. Bounds checking means verifying that a memory access stays within the intended region.

The researcher's own summary is blunt: audit every libcurl POST in your stack and treat CURLOPT_POSTFIELDS like explosives. Either switch to CURLOPT_COPYPOSTFIELDS or prove the pointer lives forever, with no exceptions. An audit here means going through your own code and checking every place you use the option.

Variants to test

  • Other transfer paths that read the POST body late. The crash here is in Curl_pretransfer() on the HTTP/3 path. Try the same out-of-scope buffer with other protocol backends and other request methods that carry a body. A positive result is an AddressSanitizer stack-use-after-scope report pointing at a libcurl frame that reads the stored pointer.
  • Language bindings that wrap CURLOPT_POSTFIELDS. Look for bindings that pass a temporary or stack-backed buffer to the option without copying. A positive result is a crash or ASAN report in the binding's POST path when the buffer's owner goes away before the transfer completes.
  • Longer-lived but still freed buffers. Instead of a stack array, free a heap buffer after curl_easy_setopt() and before curl_easy_perform(). A positive result is a heap-use-after-free report at the same strlen call in Curl_pretransfer().
  • Reuse of the same easy handle. Set CURLOPT_POSTFIELDS to a buffer, let it go out of scope, then perform more than one transfer on the handle. A positive result is the stale pointer being read on a later transfer, not only the first.
  • Timeout and cancellation paths. The reproducer sets CURLOPT_TIMEOUT_MS to 50. Vary the timing so the transfer is aborted or retried at different points. A positive result is the invalid pointer being dereferenced during cleanup or retry rather than during the initial pretransfer.

A heap-use-after-free is the same idea as a stack-use-after-scope, but for memory taken from the heap and then explicitly released. Cancellation means stopping a transfer before it finishes.

Glossary

  • API: the set of functions and options a library offers to the programs that use it.
  • AddressSanitizer (ASAN): a compiler tool that adds checks around memory accesses and reports invalid ones.
  • ARM64: a family of processor used in newer Apple Macs and many other devices.
  • Audit: a systematic review of code to find problems.
  • Binding: a wrapper that lets code in one language call a library written in another.
  • Bounds checking: verifying that a memory access stays inside the intended region.
  • Buffer: a region of memory used to hold data, such as a request body.
  • CLI: command-line interface, a program run by typing commands.
  • Clang: a C compiler.
  • Client-side: code that runs on the user's machine and talks to a server.
  • Code execution: an attacker getting their own instructions to run on a machine.
  • Compiler: a program that turns source code into a runnable program.
  • Control flow hijacking: redirecting a program so it does something other than intended.
  • curl: the command-line program built on libcurl.
  • CURLOPT_COPYPOSTFIELDS: the libcurl option that copies the POST body instead of storing a pointer.
  • CURLOPT_POSTFIELDS: the libcurl option that supplies a POST body by pointer, without copying.
  • Denial of service: making a program or service stop working.
  • Dereference: follow a pointer to read or write the memory it points at.
  • Easy handle: libcurl's object representing one transfer.
  • Embedded system: a small computer built into a device.
  • Fuzzing: feeding a program many generated inputs to find misbehaviour.
  • Harness: the wrapper program that connects a fuzzer to the code under test.
  • Heap: the memory region used for longer-lived allocations.
  • Heap-use-after-free: reading heap memory after it has been released.
  • HTTP/3: a newer version of the web protocol, built on ngtcp2 and nghttp3 in this setup.
  • Language binding: see binding.
  • libcurl: the client-side transfer library behind curl.
  • libFuzzer: a tool that automatically generates inputs to test a program.
  • Lifetime: how long a piece of memory stays valid.
  • Memory corruption: reading or writing memory in a way the program did not intend.
  • nghttp3: a library implementing HTTP/3.
  • ngtcp2: a library implementing the transport underneath HTTP/3.
  • Pointer: a value that says where in memory something is stored.
  • POST request: a web request that carries a body of data to the server.
  • Proof of concept (PoC): a minimal program that demonstrates a bug.
  • Remote exploitability: the ability to trigger a bug over a network from elsewhere.
  • Stack: the memory region used for short-lived local variables.
  • Stack trace: the list of function calls that led to a problem.
  • Stack-use-after-scope: reading stack memory after the block that owned it has ended.
  • strlen: the C function that measures a string's length by counting until a zero byte.
  • UndefinedBehaviorSanitizer: a compiler tool that flags invalid program behaviour.
  • Use-after-free: reading memory after it has been released.
  • Use-after-scope: reading memory after the block that owned it has ended.

More by geeknik

View all

79 more disclosed reports, 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.