("possible") UAF
The report claims a use-after-free in libcurl's cf_h2_proxy_ctx_free function, where a context object is freed and then accessed. An attacker could potentially cause crashes, memory corruption, or remote code execution, though the report only demonstrates the bug with a simplified standalone example.
- Disclosed after 13 hours
Title: Potential Use-After-Free Vulnerability in cf_h2_proxy_ctx_free Function of libcurl
Vulnerability Overview: A potential Use-After-Free (UAF) vulnerability has been identified in the cf_h2_proxy_ctx_free function of the libcurl library. This issue occurs when the cf_h2_proxy_ctx object is freed and then accessed shortly afterward, leading to undefined behavior, including potential crashes, memory corruption, or security vulnerabilities if exploited.
Impact:
Crashes Memory corruption Possible remote code execution or data leakage if exploited in a malicious environment. Steps to Reproduce:
Obtain libcurl: Compile and Run the Example Code: Use the simplified code below to reproduce the vulnerability. The code demonstrates freeing a context object (cf_h2_proxy_ctx) and then accessing it, leading to undefined behavior.
Example Code:
#include <stdio.h> #include <stdlib.h>
struct cf_h2_proxy_ctx { int stream_id; void *inbufq; void *outbufq; };
void cf_h2_proxy_ctx_free(struct cf_h2_proxy_ctx *ctx) { if (ctx) { printf("Freeing ctx (stream_id: %d)\n", ctx->stream_id); free(ctx); } }
void trigger_bug(struct cf_h2_proxy_ctx *ctx) { printf("Triggering bug...\n"); if (ctx) { printf("Using ctx with stream_id: %d\n", ctx->stream_id); } else { printf("Error: ctx is already freed!\n"); } }
int main() { // Simulate creating a proxy context struct cf_h2_proxy_ctx *ctx = malloc(sizeof(struct cf_h2_proxy_ctx)); if (!ctx) { perror("Failed to allocate memory for ctx"); return 1; } ctx->stream_id = 12345;
cf_h2_proxy_ctx_free(ctx);
trigger_bug(ctx);
return 0;
}
Run the Code and Observe the Output: Upon execution, the following output indicates the cf_h2_proxy_ctx object is being accessed after it has been freed:
Freeing ctx (stream_id: 12345) Using ctx with stream_id: 54321 Verify with Valgrind: To confirm the issue, run the program with Valgrind to detect any memory errors:
valgrind ./your_program Valgrind Output
Memcheck, a memory error detector ("Invalid read of size 4") at 0xxxxxx: by 0xxxxxx: Address 0xxx is 0 bytes inside a block of size 24 freed at 0xxxxxxx: free by 0xxxxxx: cf_h2_proxy_ctx_free by 0xxxxx: main
Impact
A potential Use-After-Free (UAF) vulnerability has been identified in the cf_h2_proxy_ctx_free function of the libcurl library. The issue occurs when the cf_h2_proxy_ctx object is freed and then accessed shortly after, leading to undefined behavior, including possible crashes, memory corruption, or security vulnerabilities if exploited.
"Note: I’m a beginner in this area, so please let me know if I’ve missed or misinterpreted any details, or if I’ve misunderstood the issue entirely. This report has been assisted by AI."
Context
This report concerns libcurl, the client-side URL transfer library, and specifically a function named cf_h2_proxy_ctx_free. The name suggests a connection filter (cf) context used for HTTP/2 proxying, whose free routine releases a cf_h2_proxy_ctx object. The researcher's claim is that this object can be freed and then accessed shortly afterwards, producing a use-after-free (UAF).
The report is filed against the curl source repository at https://github.com/curl/curl and is classified as Memory Corruption - Generic. It carries no severity score and no bounty, and it was disclosed on 8 February 2025. The author states plainly at the end that they are a beginner in this area and that the report was assisted by AI.
Setup
The report gives no build instructions, no curl version, no compiler flags and no configuration of the library. The only stated precondition is obtaining libcurl and compiling the example program that follows. The tools named are a C compiler (implied by the #include lines and the build of the sample) and Valgrind, used to confirm the memory error.
Finding it
The researcher identified a pattern in which a cf_h2_proxy_ctx object is released by cf_h2_proxy_ctx_free and then read again by later code. Reading a field of a structure after its storage has been returned to the allocator is undefined behaviour: the memory may still hold the old value, may have been reused, or may be unmapped. The report frames the consequence as crashes, memory corruption, and, if exploited in a malicious environment, possible remote code execution or data leakage.
What the report does not contain is any path through libcurl itself that reaches this sequence. The demonstration is a standalone program that reimplements a structure with the same name and a free function with the same name, rather than exercising the library.
Exploitation
Step 1: Obtain libcurl
The first step is simply to obtain libcurl. No version, tag or commit is specified.
Step 2: Compile and run the example code
The researcher provides a simplified program that allocates a context, frees it, and then reads a field from it:
#include <stdio.h>
#include <stdlib.h>
struct cf_h2_proxy_ctx {
int stream_id;
void *inbufq;
void *outbufq;
};
void cf_h2_proxy_ctx_free(struct cf_h2_proxy_ctx *ctx) {
if (ctx) {
printf("Freeing ctx (stream_id: %d)\n", ctx->stream_id);
free(ctx);
}
}
void trigger_bug(struct cf_h2_proxy_ctx *ctx) {
printf("Triggering bug...\n");
if (ctx) {
printf("Using ctx with stream_id: %d\n", ctx->stream_id);
} else {
printf("Error: ctx is already freed!\n");
}
}
int main() {
// Simulate creating a proxy context
struct cf_h2_proxy_ctx *ctx = malloc(sizeof(struct cf_h2_proxy_ctx));
if (!ctx) {
perror("Failed to allocate memory for ctx");
return 1;
}
ctx->stream_id = 12345;
cf_h2_proxy_ctx_free(ctx);
trigger_bug(ctx);
return 0;
}
The structure holds a stream_id and two queue pointers, inbufq and outbufq. cf_h2_proxy_ctx_free prints the stream id and calls free on the pointer. main allocates the structure, sets stream_id to 12345, frees it, and then calls trigger_bug with the same pointer. trigger_bug checks only whether the pointer is non-NULL, which it still is after free, and then reads ctx->stream_id. That read is the use after free. The NULL check does not help, because free does not modify the caller's pointer.
Step 3: Observe the output
The researcher reports the following output, which they present as evidence that the object is accessed after being freed:
Freeing ctx (stream_id: 12345)
Using ctx with stream_id: 54321
The second line shows a different value from the one stored. The report does not explain what produced the new value.
Step 4: Verify with Valgrind
The program is then run under Valgrind:
valgrind ./your_program
The reported Valgrind output is:
Memcheck, a memory error detector
("Invalid read of size 4")
at 0xxxxxx:
by 0xxxxxx:
Address 0xxx is 0 bytes inside a block of size 24 freed
at 0xxxxxxx: free
by 0xxxxxx: cf_h2_proxy_ctx_free
by 0xxxxx: main
Memcheck reports an invalid read of size 4, which matches the width of the int stream_id field, at an address inside a 24-byte block that was freed. The free stack names cf_h2_proxy_ctx_free called from main. The addresses are shown as placeholders, so the trace cannot be tied to a specific build.
Root cause
The defect demonstrated is the classic one: a pointer is passed to free and then dereferenced. The guard in trigger_bug tests the pointer against NULL rather than tracking whether the object is still alive, so it cannot detect the stale reference. In the sample, the free and the use are adjacent in main, which makes the ordering obvious.
Whether libcurl's own cf_h2_proxy_ctx_free has a caller that subsequently touches the same context is not shown. The report asserts that the issue occurs in that function but provides no call path inside the library, no HTTP/2 proxy configuration and no request that triggers it. The sample program defines its own structure and function with those names, so it demonstrates the pattern rather than the library's behaviour. The report also does not describe any existing defence, such as reference counting or nulling the pointer after free, that would or would not have prevented it.
Impact
The report lists crashes, memory corruption, and possible remote code execution or data leakage if exploited in a malicious environment. These are stated as possibilities conditional on exploitation. No attack scenario is given: there is no description of who could reach the vulnerable path, what input would be required, or which curl features (for example an HTTP/2 proxy connection) would need to be in use. Given that the demonstration is a standalone program, the practical impact on libcurl users is not established in the report.
Fix
The report proposes no fix and does not say whether any change was made. The general remedy for this pattern is to stop using the pointer after it has been freed, for example by clearing the owning reference when the context is released, or by using a reference count so the object outlives every user. Which of these, if any, applies to libcurl's connection filter code is not stated here.
Variants to test
- Trace the real call path. Search the curl source for callers of
cf_h2_proxy_ctx_freeand check whether any of them touch the context afterwards. A positive result is a code path where a field of the context is read after the free, reachable from a normal HTTP/2 proxy connection. - Exercise the library, not a copy. Build curl with an HTTP/2 proxy configured and run it under Valgrind or AddressSanitizer. A positive result is an invalid read report whose stack includes the connection filter code rather than only a test harness.
- Check the free routine's own contract. Confirm whether the free function clears the pointer held by its owner. A positive result is an owner that keeps a dangling pointer after the free returns.
- Look for the same pattern in sibling connection filters. Other
cf_*_ctx_freeroutines may share the structure. A positive result is another filter whose context is freed while still referenced. - Re-run the sample with the allocator perturbed. Allocate and free intervening blocks so the freed 24-byte region is reused before the read. A positive result is a crash or a clearly corrupted value, which confirms the read is genuinely stale rather than reading untouched memory.
What happened, in plain words
Someone filed a bug report against curl, a very widely used piece of software that fetches things from the internet. The report says that a part of curl called libcurl has a memory bug: a small block of memory is thrown away and then read again afterwards. In programming this is called a use-after-free, and it can make a program crash or behave unpredictably.
The report is written by someone who says openly that they are new to this area and that an AI helped them write it. It was filed on the curl source code repository on GitHub, was given no severity score and no reward, and was made public on 8 February 2025.
What the report actually contains is a small standalone program that copies the names of two things inside curl and shows the use-after-free pattern in that copy. It does not show a way to make real curl do it. That distinction matters a lot, and this article walks through the report step by step so you can see exactly what was shown and what was not.
Some background first
What curl and libcurl are
curl is a command-line tool you can use to download a web page or call a web service from a terminal. libcurl is the library underneath it: a collection of ready-made code that other programs can link against so they can make network requests without writing all the low-level plumbing themselves. A library, in everyday terms, is like a box of tools you borrow rather than build. The report is filed against the curl source code, which lives at https://github.com/curl/curl.
What HTTP/2 and a proxy are
HTTP/2 is a newer version of the protocol browsers and servers use to exchange web pages. A proxy is a middleman server: instead of connecting straight to the destination, your program connects to the proxy and asks it to fetch things on your behalf. Companies often use proxies to control or log outbound traffic. The report's title mentions HTTP/2 proxying because the function it names appears to belong to that part of curl.
What a use-after-free is
When a program needs memory for something, it asks the operating system for a chunk and gets back an address (a pointer) to it. When it is finished, it hands the chunk back with a free call. After that, the chunk no longer belongs to the program; it may be handed to something else, or the operating system may take it away entirely.
A use-after-free happens when the program keeps the old address and reads or writes through it after handing the memory back. The everyday comparison: you check out a hotel room, check out, and then walk back in later using the old key card. Sometimes the room is empty and nothing bad happens, sometimes a new guest is inside and you see their things, and sometimes the lock has been changed and the door refuses to open (a crash). Programmers call this undefined behaviour, meaning the language makes no promise about what will happen.
What Valgrind is
Valgrind is a free tool that runs a program in a kind of slow-motion sandbox and watches every memory access. One of its components, Memcheck, flags reads and writes to memory that has already been freed. It is the standard way to prove that a use-after-free really happened rather than just suspecting it.
The claim in the report
The report says a function called cf_h2_proxy_ctx_free in libcurl frees an object of type cf_h2_proxy_ctx, and that the same object is then accessed shortly afterwards. Reading the name piece by piece: cf likely stands for connection filter, h2 for HTTP/2, proxy for the proxy feature, ctx for context (a bundle of state that belongs to one connection), and _free for the routine that releases it. The report does not confirm any of that from the curl source; it is what the name suggests.
The stated consequences are crashes, memory corruption, and, if someone exploited it in a malicious environment, possibly remote code execution (an attacker running their own code on your machine) or data leakage (an attacker reading data they should not see).
Setting up
The report gives no build instructions, no curl version, no compiler flags and no library configuration. The only stated precondition is obtaining libcurl and compiling the example program that follows. The tools involved are a C compiler (implied by the #include lines and by the fact that the sample has to be built) and Valgrind, used to confirm the memory error.
Step by step through the report
Step 1: Obtain libcurl
The first step is simply to obtain libcurl. No version, tag or commit is named, so there is nothing to pin the test to.
Step 2: Compile and run the example code
The researcher provides a simplified program that allocates a context, frees it, and then reads a field from it. Here it is exactly as given:
#include <stdio.h>
#include <stdlib.h>
struct cf_h2_proxy_ctx {
int stream_id;
void *inbufq;
void *outbufq;
};
void cf_h2_proxy_ctx_free(struct cf_h2_proxy_ctx *ctx) {
if (ctx) {
printf("Freeing ctx (stream_id: %d)\n", ctx->stream_id);
free(ctx);
}
}
void trigger_bug(struct cf_h2_proxy_ctx *ctx) {
printf("Triggering bug...\n");
if (ctx) {
printf("Using ctx with stream_id: %d\n", ctx->stream_id);
} else {
printf("Error: ctx is already freed!\n");
}
}
int main() {
// Simulate creating a proxy context
struct cf_h2_proxy_ctx *ctx = malloc(sizeof(struct cf_h2_proxy_ctx));
if (!ctx) {
perror("Failed to allocate memory for ctx");
return 1;
}
ctx->stream_id = 12345;
cf_h2_proxy_ctx_free(ctx);
trigger_bug(ctx);
return 0;
}
Line by line, in plain words:
#include <stdio.h>and#include <stdlib.h>pull in standard C headers: one for printing to the screen, one for memory allocation and freeing.struct cf_h2_proxy_ctx { ... };defines a custom data type. Think of a struct as a form with named fields. This one has three:stream_id, an integer; andinbufqandoutbufq, two pointers (addresses of other memory). The names match the ones the report attributes to curl, but this is a fresh definition written for the demo, not curl's own.void cf_h2_proxy_ctx_free(struct cf_h2_proxy_ctx *ctx)is a function that takes a pointer to one of those structs. If the pointer is not NULL (the special value meaning "points at nothing"), it prints the stream id and then callsfree(ctx), handing the memory back.void trigger_bug(struct cf_h2_proxy_ctx *ctx)is the function that does the bad read. It prints a message, then checksif (ctx). That check only asks "is this pointer not NULL?", not "is this memory still mine?". Sincefreedoes not change the caller's pointer, the check passes, and the next line readsctx->stream_idfrom memory that has already been returned.int main()is where the program starts. It asks for memory withmalloc(sizeof(struct cf_h2_proxy_ctx)), which reserves enough bytes for the struct. If that fails it prints an error and exits.ctx->stream_id = 12345;stores a known value so we can recognise it later.cf_h2_proxy_ctx_free(ctx);frees the memory.trigger_bug(ctx);passes the same, now stale, pointer to the function that reads from it. That is the use after free.
The key lesson is that the NULL check does not help. A pointer is just a number (an address); freeing the memory does not set that number to zero. To avoid the bug you would have to stop using the pointer, or set it to NULL yourself after freeing, or use a scheme like reference counting where the object is only freed once nobody holds it any more.
Step 3: Observe the output
The researcher reports the following output, presented as evidence that the object is accessed after being freed:
Freeing ctx (stream_id: 12345)
Using ctx with stream_id: 54321
The first line is expected: the free routine printed the value 12345 that was stored. The second line is the interesting one. It shows 54321, a different number from the one that was written. That is a different number from the one that was written, which is the kind of unpredictable result a use-after-free can produce. The report does not explain what produced the new value.
Step 4: Verify with Valgrind
The program is then run under Valgrind:
valgrind ./your_program
valgrind is the tool; ./your_program is the compiled sample sitting in the current directory. The reported Valgrind output is:
Memcheck, a memory error detector
("Invalid read of size 4")
at 0xxxxxx:
by 0xxxxxx:
Address 0xxx is 0 bytes inside a block of size 24 freed
at 0xxxxxxx: free
by 0xxxxxx: cf_h2_proxy_ctx_free
by 0xxxxx: main
Reading it in plain words:
Memcheck, a memory error detectoris Valgrind announcing itself.Invalid read of size 4means the program read 4 bytes from memory it was not allowed to touch. Four bytes is the size of aninton most systems, which matches thestream_idfield.- The
atandbylines are the stack trace of where the read happened. The addresses are shown as placeholders (0xxxxxx), so the trace cannot be tied to a specific build. Address 0xxx is 0 bytes inside a block of size 24 freedsays the read landed at the very start of a 24-byte block that had already been freed. Twenty-four bytes is the size of the struct in the sample.- The
freestack namescf_h2_proxy_ctx_freecalled frommain, which is the free that released the block.
Taken at face value, this describes a read of the right size, at the right place, in a block that was freed by the function the report names.
Why it happens
The defect demonstrated is the classic one: a pointer is passed to free and then dereferenced. The guard in trigger_bug tests the pointer against NULL rather than tracking whether the object is still alive, so it cannot detect the stale reference. In the sample, the free and the use sit next to each other in main, which makes the ordering obvious.
The demonstration is a standalone program that reimplements a structure with the same name and a free function with the same name, rather than exercising the library. There is no call path inside curl, no HTTP/2 proxy configuration and no request that triggers it. The report also does not describe any existing defence, such as reference counting or nulling the pointer after free, that would or would not have prevented it.
Impact
The report lists crashes, memory corruption, and possible remote code execution or data leakage if exploited in a malicious environment. These are stated as possibilities conditional on exploitation. No attack scenario is given: there is no description of who could reach the vulnerable path, what input would be required, or which curl features (for example an HTTP/2 proxy connection) would need to be in use. Given that the demonstration is a standalone program, the practical impact on libcurl users is not established in the report.
Fix
The report proposes no fix and does not say whether any change was made. The general remedy for this pattern is to stop using the pointer after it has been freed, for example by clearing the owning reference when the context is released, or by using a reference count so the object outlives every user. Which of these, if any, applies to libcurl's connection filter code is not stated here.
What to test next
If you wanted to take this further, here are the directions the report leaves open. Each one is a way to turn a suspicion into evidence.
- Trace the real call path. Search the curl source for callers of
cf_h2_proxy_ctx_freeand check whether any of them touch the context afterwards. A positive result is a code path where a field of the context is read after the free, reachable from a normal HTTP/2 proxy connection. - Exercise the library, not a copy. Build curl with an HTTP/2 proxy configured and run it under Valgrind or AddressSanitizer (another memory-checking tool). A positive result is an invalid read report whose stack includes the connection filter code rather than only a test harness.
- Check the free routine's own contract. Confirm whether the free function clears the pointer held by its owner. A positive result is an owner that keeps a dangling pointer after the free returns.
- Look for the same pattern in sibling connection filters. Other
cf_*_ctx_freeroutines may share the structure. A positive result is another filter whose context is freed while still referenced. - Re-run the sample with the allocator perturbed. Allocate and free intervening blocks so the freed 24-byte region is reused before the read. A positive result is a crash or a clearly corrupted value, which confirms the read is genuinely stale rather than reading untouched memory.
Glossary
- libcurl: the library part of curl that other programs link against to make network requests.
- curl: a command-line tool and library for transferring data over URLs.
- HTTP/2: a version of the web protocol that carries pages between clients and servers.
- Proxy: a middleman server that fetches things on your behalf.
- Connection filter: a layer inside curl that processes a connection, suggested by the
cfprefix in the function name. - Context (
ctx): a bundle of state that belongs to one connection or operation. - Pointer: a number that is the address of a piece of memory.
malloc: the C function that asks the operating system for a block of memory.free: the C function that hands a block of memory back.- Use-after-free (UAF): reading or writing memory after it has been freed.
- Undefined behaviour: a situation where the programming language makes no promise about what will happen.
- Memory corruption: damage to memory contents caused by writing where you should not.
- Remote code execution (RCE): an attacker running their own code on a victim's machine.
- Data leakage: an attacker reading data they should not be able to see.
- Valgrind / Memcheck: a tool that runs a program and reports invalid memory accesses.
- AddressSanitizer: another tool that detects memory errors at runtime.
- Stack trace: the list of function calls that led to a particular point in a program.
- NULL: the special pointer value meaning "points at nothing".
- Reference counting: a scheme where an object is only freed once no one holds a reference to it.
- Dangling pointer: a pointer that still holds an address after the memory there has been freed.
- Struct: a custom data type that groups named fields together.
- Integer (
int): a whole-number type in C, typically 4 bytes wide. - Severity score / CVSS: a number used to rate how serious a vulnerability is.
- Bounty: a reward paid to a researcher for reporting a vulnerability.
- Disclosure: the point at which a vulnerability report is made public.