Use-After-Free in SMB connection reuse (req->path dangling pointer after needle destruction)
A heap-use-after-free occurs in curl's SMB handling when two SMB URLs to the same host are processed, because a pointer into freed connection memory is later read. An attacker could cause a crash (denial of service) and potentially information disclosure or further memory corruption if the freed memory is reallocated.
- Disclosed after 52 days
Summary
A heap-use-after-free occurs in smb_send_open() at lib/smb.c when curl processes two SMB URLs targeting the same host. The function smb_parse_url_path() sets req->path as a non-owning pointer into smbc->share (connection-owned memory). During connection reuse, the needle connection is freed via Curl_conn_free() → smb_conn_dtor(), which frees smbc->share, but req->path (on the easy handle) still references the freed buffer. The subsequent strlen(req->path) in smb_send_open() reads freed heap memory.
Affected Version
curl 8.19.0-DEV (master branch, built March 8 2026) Platform: Ubuntu 22.04 on x86_64 (WSL2) Built with: gcc, OpenSSL, --enable-smb, -fsanitize=address
Steps To Reproduce
- Clone and build curl from master with ASAN and SMB enabled:
git clone https://github.com/curl/curl.git && cd curl
autoreconf -fi
./configure --with-openssl --enable-smb --without-libpsl
make CFLAGS="-fsanitize=address -g -O0 -fno-omit-frame-pointer" LDFLAGS="-fsanitize=address" -j$(nproc)
- Start the attached fake SMB server (fake_smb_server.py) in one terminal:
python3 fake_smb_server.py 5445
- In another terminal, run curl with two SMB URLs to the same host:
ASAN_OPTIONS=detect_leaks=0 LD_LIBRARY_PATH=./lib/.libs \
./src/.libs/curl -u guest:guest \
"smb://127.0.0.1:5445/share1/file1" -o /dev/null \
"smb://127.0.0.1:5445/share2/file2" -o /dev/null
- ASAN reports heap-use-after-free in smb_send_open.
Root Cause
In smb_parse_url_path() (lib/smb.c ~line 398-435):
smbc->share = strdup(path)allocates "share2/file2" (13 bytes)- The
/is replaced with\0, splitting it into "share2\0file2\0" req->path = slashpoints 7 bytes intosmbc->share
When the second URL reuses the pooled connection from URL #1:
url_find_or_create_conn()finds a match and frees the needle connectionCurl_conn_free()→smb_conn_dtor()→free(smbc->share)req->pathnow dangles into freed heap
Then smb_request_state() → smb_send_open():
const size_t byte_count = strlen(req->path) + 1; // UAF read
ASAN confirms: "0x502000002a57 is located 7 bytes inside of 13-byte region, freed by smb_conn_dtor, previously allocated by smb_parse_url_path via strdup"
ASAN Output
==519095==ERROR: AddressSanitizer: heap-use-after-free on address 0x502000002a57 at pc 0x7967a543daa7 bp 0x7fffdbfd8b00 sp 0x7fffdbfd82a8
READ of size 1 at 0x502000002a57 thread T0
#0 0x7967a543daa6 in __interceptor_strlen
#1 0x7967a51a4326 in smb_send_open (libcurl.so.4)
#2 0x7967a51a75fe in smb_request_state (libcurl.so.4)
#3 0x7967a5158fbf in protocol_doing (libcurl.so.4)
#4 0x7967a515d395 in multi_runsingle (libcurl.so.4)
#5 0x7967a515e569 in multi_perform (libcurl.so.4)
#6 0x7967a515ebe0 in curl_multi_perform (libcurl.so.4)
#7 0x7967a50bc841 in easy_transfer (libcurl.so.4)
#8 0x7967a50bcf0a in easy_perform (libcurl.so.4)
#9 0x7967a50bcffe in curl_easy_perform (libcurl.so.4)
#10 0x5d0efa2f6ea2 in serial_transfers (curl)
#11 0x5d0efa2f80b2 in run_all_transfers (curl)
#12 0x5d0efa2f8cd6 in operate (curl)
#13 0x5d0efa2ea7b4 in main (curl)
freed by thread T0 here:
#0 __interceptor_free
#1 smb_conn_dtor (libcurl.so.4)
#2 hash_elem_clear_ptr (libcurl.so.4)
#3 hash_elem_destroy (libcurl.so.4)
#4 Curl_hash_clean (libcurl.so.4)
#5 Curl_hash_destroy (libcurl.so.4)
#6 Curl_conn_free (libcurl.so.4)
#7 url_find_or_create_conn (libcurl.so.4)
previously allocated by thread T0 here:
#0 __interceptor_strdup
#1 smb_parse_url_path (libcurl.so.4)
#2 smb_setup_connection (libcurl.so.4)
#3 setup_connection_internals (libcurl.so.4)
#4 url_create_needle (libcurl.so.4)
#5 url_find_or_create_conn (libcurl.so.4)
SUMMARY: AddressSanitizer: heap-use-after-free in __interceptor_strlen
0x502000002a57 is located 7 bytes inside of 13-byte region [0x502000002a50,0x502000002a5d)
Impact
Heap-use-after-free (CWE-416) triggered by a simple two-URL curl command line. Requires no authentication to a real SMB server - the UAF occurs client-side before any server response to the second request. This results in a guaranteed crash (DoS). If the freed 13-byte heap region is reallocated with attacker-influenced data before the read, it could potentially lead to information disclosure or further memory corruption.
Attachments
Context
curl speaks a number of protocols beyond HTTP, and SMB is one of them. The SMB backend lives in lib/smb.c and drives a small state machine (smb_request_state()) that walks a request through connect, negotiate, session setup, tree connect and finally open. The open step is smb_send_open(), which builds the SMB open request for a file inside a share.
To build that request, the SMB code needs the path of the file relative to the share. smb_parse_url_path() produces it by duplicating the URL path into connection-owned memory (smbc->share) and then splitting it in place, so that the share name and the file path are two NUL-terminated strings inside one allocation. The file part is stored on the easy handle as req->path, and it is a non-owning pointer into that allocation: the easy handle does not own the buffer, the connection does.
That ownership split is fine as long as the connection outlives the request. The bug is what happens when it does not.
Setup
The researcher worked on curl 8.19.0-DEV, master branch, built on 8 March 2026, on Ubuntu 22.04 x86_64 under WSL2, with gcc and OpenSSL, configured with --enable-smb and built with AddressSanitizer.
No SMB server, credentials or account is needed. The reproducer uses a fake SMB server script (fake_smb_server.py, attached to the report) listening on a local port, and the built-in guest account name on the curl command line. The crash happens client-side, so the server only has to be there to let the connection be established and pooled.
Finding it
The trigger is a single curl invocation with two SMB URLs pointing at the same host. curl processes them serially, and the second transfer reuses the connection that the first one left in the connection pool. During that reuse, the connection that the pool lookup matched is freed, and with it the smbc->share buffer. But the easy handle for the second URL already had req->path pointing into that buffer, set when its own connection was set up. The pointer is now dangling, and the next strlen(req->path) in smb_send_open() reads freed heap memory.
What makes it look wrong is that nothing about the two URLs is unusual: same host, different shares, different files, plain command line. There is no malformed input and no server interaction required beyond the connection being established.
Exploitation
Step 1: build curl with ASAN and SMB
git clone https://github.com/curl/curl.git && cd curl
autoreconf -fi
./configure --with-openssl --enable-smb --without-libpsl
make CFLAGS="-fsanitize=address -g -O0 -fno-omit-frame-pointer" LDFLAGS="-fsanitize=address" -j$(nproc)
This produces a curl and libcurl instrumented with AddressSanitizer, with the SMB protocol compiled in, so that the use-after-free is reported with allocation and free stacks instead of silently reading whatever is in the heap.
Step 2: start the fake SMB server
python3 fake_smb_server.py 5445
The script is started on port 5445.
Step 3: run curl with two SMB URLs to the same host
ASAN_OPTIONS=detect_leaks=0 LD_LIBRARY_PATH=./lib/.libs \
./src/.libs/curl -u guest:guest \
"smb://[redacted]:5445/share1/file1" -o /dev/null \
"smb://[redacted]:5445/share2/file2" -o /dev/null
Both URLs target the same host and port, so the second transfer is a candidate for connection reuse. -u guest:guest supplies the credentials, -o /dev/null discards the output, and LD_LIBRARY_PATH points the binary at the freshly built libcurl.
Step 4: read the ASAN report
ASAN reports a heap-use-after-free in smb_send_open:
==519095==ERROR: AddressSanitizer: heap-use-after-free on address 0x502000002a57 at pc 0x7967a543daa7 bp 0x7fffdbfd8b00 sp 0x7fffdbfd82a8
READ of size 1 at 0x502000002a57 thread T0
#0 0x7967a543daa6 in __interceptor_strlen
#1 0x7967a51a4326 in smb_send_open (libcurl.so.4)
#2 0x7967a51a75fe in smb_request_state (libcurl.so.4)
#3 0x7967a5158fbf in protocol_doing (libcurl.so.4)
#4 0x7967a515d395 in multi_runsingle (libcurl.so.4)
#5 0x7967a515e569 in multi_perform (libcurl.so.4)
#6 0x7967a515ebe0 in curl_multi_perform (libcurl.so.4)
#7 0x7967a50bc841 in easy_transfer (libcurl.so.4)
#8 0x7967a50bcf0a in easy_perform (libcurl.so.4)
#9 0x7967a50bcffe in curl_easy_perform (libcurl.so.4)
#10 0x5d0efa2f6ea2 in serial_transfers (curl)
#11 0x5d0efa2f80b2 in run_all_transfers (curl)
#12 0x5d0efa2f8cd6 in operate (curl)
#13 0x5d0efa2ea7b4 in main (curl)
freed by thread T0 here:
#0 __interceptor_free
#1 smb_conn_dtor (libcurl.so.4)
#2 hash_elem_clear_ptr (libcurl.so.4)
#3 hash_elem_destroy (libcurl.so.4)
#4 Curl_hash_clean (libcurl.so.4)
#5 Curl_hash_destroy (libcurl.so.4)
#6 Curl_conn_free (libcurl.so.4)
#7 url_find_or_create_conn (libcurl.so.4)
previously allocated by thread T0 here:
#0 __interceptor_strdup
#1 smb_parse_url_path (libcurl.so.4)
#2 smb_setup_connection (libcurl.so.4)
#3 setup_connection_internals (libcurl.so.4)
#4 url_create_needle (libcurl.so.4)
#5 url_find_or_create_conn (libcurl.so.4)
SUMMARY: AddressSanitizer: heap-use-after-free in __interceptor_strlen
0x502000002a57 is located 7 bytes inside of 13-byte region [0x502000002a50,0x502000002a5d)
The three stacks tell the whole story. The read happens in strlen called from smb_send_open, reached through smb_request_state and the normal multi/easy transfer path. The free happens in smb_conn_dtor, reached from Curl_conn_free called by url_find_or_create_conn, that is, during the connection reuse lookup. The allocation happened in smb_parse_url_path, called from smb_setup_connection when the connection was first set up. The faulting address sits 7 bytes inside a 13-byte region, which matches the offset of the file part inside the duplicated path.
Root cause
In smb_parse_url_path() (lib/smb.c, around lines 398 to 435), the path is duplicated into connection-owned memory and then split in place:
smbc->share = strdup(path)allocates"share2/file2", 13 bytes.- The
/is replaced with\0, splitting the buffer into"share2\0file2\0". req->path = slashpoints 7 bytes intosmbc->share, at the start offile2.
So req->path is a borrowed pointer into memory owned by the SMB connection, stored on the easy handle. When the second URL reuses the pooled connection from the first URL:
url_find_or_create_conn()finds a match and frees the needle connection.Curl_conn_free()callssmb_conn_dtor(), which callsfree(smbc->share).req->pathnow dangles into freed heap.
Then smb_request_state() reaches smb_send_open(), which does:
const size_t byte_count = strlen(req->path) + 1; // UAF read
ASAN confirms the layout: the address is 7 bytes inside a 13-byte region, freed by smb_conn_dtor and previously allocated by smb_parse_url_path via strdup.
The design flaw is the ownership mismatch: the easy handle keeps a pointer into connection-owned memory across a point where the connection can be destroyed. Nothing in the reuse path invalidates or re-derives req->path when the connection it points into is freed, so the dangling pointer survives into the next state machine step.
Impact
The report classifies this as a heap-use-after-free (CWE-416) reachable from a simple two-URL curl command line. No authentication to a real SMB server is required: the UAF occurs client-side before any server response to the second request. The immediate result is a guaranteed crash, a denial of service.
The researcher also notes that if the freed 13-byte heap region is reallocated with attacker-influenced data before the read, it could potentially lead to information disclosure or further memory corruption. That part is stated as a possibility, not demonstrated.
Fix
The report does not describe a fix or a patch.
Variants to test
- Other protocols with borrowed path pointers. Look for handlers that store a pointer into connection-owned memory on the easy handle and then allow the connection to be freed during reuse. A positive result is an ASAN use-after-free report whose free stack goes through a connection destructor and whose allocation stack goes through the protocol's URL parser.
- More than two URLs. Try three or more SMB URLs to the same host with different shares. A positive result is the same UAF, possibly on a later transfer, showing the bug is not limited to the second URL.
- Mixed hosts and ports. Vary host and port between URLs to see which combinations still hit the reuse path. A positive result is the UAF appearing whenever the pool lookup matches and frees the needle connection.
- Heap grooming before the read. Arrange allocations between the free and the
strlenso the freed region is reused. A positive result is the read returning data from the new allocation rather than crashing immediately, which is the precondition for the information disclosure the report mentions.
What happened, in plain words
curl is a command-line tool that fetches things over the internet. Most people know it for downloading web pages, but it also speaks other protocols, and one of them is SMB, the file-sharing protocol used on Windows networks. This report is about a memory bug in curl's SMB support: under a specific, ordinary set of circumstances, curl reads a piece of memory that it has already handed back to the system. That kind of bug is called a use-after-free, and it can crash the program.
The trigger is not exotic. It is a single curl command with two SMB URLs pointing at the same server. curl finishes the first one, keeps the network connection open in a pool for later, then starts the second one and reuses that pooled connection. Somewhere in that reuse, a small block of memory holding part of the second URL's path is freed, but a pointer to it is left behind and used anyway. The program then reads from memory it no longer owns.
To make the bug visible, the researcher built curl with a tool called AddressSanitizer (ASAN), which watches memory use and shouts loudly when a program touches memory it has already freed. Without ASAN the bug might pass silently or crash unpredictably; with ASAN it produces a clear report naming the exact function and the exact byte.
Background you need first
A few ideas come up again and again below, so here they are from zero.
- curl is a program you run in a terminal. You give it a URL and it fetches it. It is also a library,
libcurl, that other programs embed. The command-line tool and the library share the same code. - SMB (Server Message Block) is the protocol Windows uses to share files and printers over a network. A URL like
smb://host/share/filemeans "on this host, in this share (a shared folder), open this file". - A protocol is an agreed language two computers use to talk. HTTP is the web's language; SMB is the file-sharing language. curl has separate code for each.
- Memory, the heap, and pointers. When a program needs memory at runtime it asks the operating system for a chunk from an area called the heap. It gets back an address, called a pointer, and uses that address to read and write the chunk. When it is done, it calls
free()to hand the chunk back. After that, the address is invalid: the chunk may be reused by something else. - Use-after-free (UAF) is what happens when a program keeps using an address after freeing the memory behind it. It is like cancelling a hotel booking, then walking into the room anyway: someone else may now be in there, or the room may be empty and you trip over the furniture. The formal catalogue number for this class of bug is CWE-416.
- Dangling pointer is the name for a pointer whose target has been freed. It still holds the old address; it just no longer points at anything the program owns.
- A crash and a denial of service (DoS). If a program reads memory it should not, it may crash. A bug that reliably crashes a program is a denial of service: an attacker can stop the program from working.
- AddressSanitizer (ASAN) is a debugging tool built into the compiler. It adds checks around every memory access. When a program reads or writes freed memory, ASAN stops it and prints a report with three useful stacks: where the bad read happened, where the memory was freed, and where it was originally allocated.
- A stack trace is a list of function calls, newest at the top, showing how the program got to the point of interest. Reading one is like reading a receipt: each line is a step that led to the current moment.
- A connection pool. Opening a network connection is slow, so curl keeps finished connections around in a pool and reuses them for later requests to the same host. This is a normal optimisation; the bug lives in how SMB handles it.
- An easy handle. In libcurl, an "easy handle" is the object that represents one transfer. It holds the URL, options, and some per-transfer state. It is separate from the connection object, which represents the actual socket and protocol state.
- Ownership. In C, when one part of a program allocates memory, that part is responsible for freeing it. If another part keeps a pointer to it without owning it, that is a borrowed pointer. Borrowed pointers are fine as long as the owner lives long enough. The bug here is exactly a borrowed pointer outliving its owner.
Context: where the bug lives
curl's SMB support lives in a source file called lib/smb.c. It works as a small state machine: a function called smb_request_state() walks a request through a series of steps, one per call, until the request is done. The steps are connect, negotiate, session setup, tree connect, and finally open. The open step is a function called smb_send_open(), which builds the SMB message that asks the server to open a file inside a share.
To build that message, the SMB code needs the path of the file relative to the share. A function called smb_parse_url_path() produces it. It takes the path part of the URL (for example share2/file2), duplicates it into memory owned by the connection object (a field called smbc->share), and then splits it in place: it replaces the slash with a NUL byte, the C convention for "end of string". The result is two strings packed into one allocation: share2 and file2, back to back.
The file part is then stored on the easy handle as req->path. Crucially, req->path is a borrowed pointer into that same allocation. The easy handle does not own the buffer; the connection does. That arrangement is fine as long as the connection lives at least as long as the request. The bug is what happens when it does not.
Setup: what the researcher used
The researcher worked on curl 8.19.0-DEV, the master branch, built on 8 March 2026. The machine was Ubuntu 22.04 on x86_64, running under WSL2 (Windows Subsystem for Linux, which lets you run Linux inside Windows). The compiler was gcc, the TLS library was OpenSSL, and the build was configured with --enable-smb and instrumented with AddressSanitizer.
No real SMB server, credentials, or account is needed. The reproducer uses a fake SMB server script (fake_smb_server.py, attached to the report) listening on a local port, plus the built-in guest account name on the curl command line. The crash happens on the client side, so the server only has to be there long enough for the connection to be established and put into the pool.
Finding it: the shape of the trigger
The trigger is a single curl invocation with two SMB URLs pointing at the same host. curl processes them one after the other. The second transfer reuses the connection that the first one left in the pool. During that reuse, the connection that the pool lookup matched is freed, and with it the smbc->share buffer. But the easy handle for the second URL already had req->path pointing into that buffer, set when its own connection was set up. The pointer is now dangling, and the next strlen(req->path) in smb_send_open() reads freed heap memory.
What makes it look wrong is that nothing about the two URLs is unusual: same host, different shares, different files, plain command line. There is no malformed input and no server interaction required beyond the connection being established.
Reproducing it step by step
Step 1: build curl with ASAN and SMB
git clone https://github.com/curl/curl.git && cd curl
autoreconf -fi
./configure --with-openssl --enable-smb --without-libpsl
make CFLAGS="-fsanitize=address -g -O0 -fno-omit-frame-pointer" LDFLAGS="-fsanitize=address" -j$(nproc)
Line by line:
git clone https://github.com/curl/curl.git && cd curldownloads the curl source code from GitHub and moves into the new folder. You need the source, not a prebuilt binary, because you are going to compile it yourself with special flags.autoreconf -firegenerates the build scripts that come with the source tree. This is a standard first step when building from a git checkout rather than a release tarball../configure --with-openssl --enable-smb --without-libpslprepares the build.--with-openssluses OpenSSL for TLS,--enable-smbturns on the SMB protocol (which is off by default in some builds), and--without-libpslskips an optional library so the build is simpler.make CFLAGS="-fsanitize=address -g -O0 -fno-omit-frame-pointer" LDFLAGS="-fsanitize=address" -j$(nproc)compiles everything. TheCFLAGSadd AddressSanitizer (-fsanitize=address), debug symbols (-g), no optimisation (-O0, so the code matches the source line by line), and frame pointers (so stack traces are readable).LDFLAGSlink the ASAN runtime in.-j$(nproc)uses all CPU cores to speed up the build.
The result is a curl and libcurl instrumented with ASAN, with SMB compiled in, so that the use-after-free is reported with allocation and free stacks instead of silently reading whatever is in the heap.
Step 2: start the fake SMB server
python3 fake_smb_server.py 5445
This runs the attached Python script on port 5445. That is all that is needed: the connection has to be established so it can be pooled and then reused.
Step 3: run curl with two SMB URLs to the same host
ASAN_OPTIONS=detect_leaks=0 LD_LIBRARY_PATH=./lib/.libs \
./src/.libs/curl -u guest:guest \
"smb://[redacted]:5445/share1/file1" -o /dev/null \
"smb://[redacted]:5445/share2/file2" -o /dev/null
Line by line:
LD_LIBRARY_PATH=./lib/.libstells the operating system to load the freshly built libcurl from the build directory instead of any system-installed copy. Without this, the binary might link against an older libcurl and the bug would not appear../src/.libs/curlruns the just-built curl binary.-u guest:guestsupplies a username and password."smb://[redacted]:5445/share1/file1" -o /dev/nullis the first URL.[redacted]is the local machine,5445is the port the fake server listens on,share1is the share,file1is the file.-o /dev/nullthrows the output away."smb://[redacted]:5445/share2/file2" -o /dev/nullis the second URL. Same host and port, different share and file. Because the host and port match, the second transfer is a candidate for connection reuse, which is exactly what triggers the bug.
Step 4: read the ASAN report
ASAN reports a heap-use-after-free in smb_send_open:
==519095==ERROR: AddressSanitizer: heap-use-after-free on address 0x502000002a57 at pc 0x7967a543daa7 bp 0x7fffdbfd8b00 sp 0x7fffdbfd82a8
READ of size 1 at 0x502000002a57 thread T0
#0 0x7967a543daa6 in __interceptor_strlen
#1 0x7967a51a4326 in smb_send_open (libcurl.so.4)
#2 0x7967a51a75fe in smb_request_state (libcurl.so.4)
#3 0x7967a5158fbf in protocol_doing (libcurl.so.4)
#4 0x7967a515d395 in multi_runsingle (libcurl.so.4)
#5 0x7967a515e569 in multi_perform (libcurl.so.4)
#6 0x7967a515ebe0 in curl_multi_perform (libcurl.so.4)
#7 0x7967a50bc841 in easy_transfer (libcurl.so.4)
#8 0x7967a50bcf0a in easy_perform (libcurl.so.4)
#9 0x7967a50bcffe in curl_easy_perform (libcurl.so.4)
#10 0x5d0efa2f6ea2 in serial_transfers (curl)
#11 0x5d0efa2f80b2 in run_all_transfers (curl)
#12 0x5d0efa2f8cd6 in operate (curl)
#13 0x5d0efa2ea7b4 in main (curl)
freed by thread T0 here:
#0 __interceptor_free
#1 smb_conn_dtor (libcurl.so.4)
#2 hash_elem_clear_ptr (libcurl.so.4)
#3 hash_elem_destroy (libcurl.so.4)
#4 Curl_hash_clean (libcurl.so.4)
#5 Curl_hash_destroy (libcurl.so.4)
#6 Curl_conn_free (libcurl.so.4)
#7 url_find_or_create_conn (libcurl.so.4)
previously allocated by thread T0 here:
#0 __interceptor_strdup
#1 smb_parse_url_path (libcurl.so.4)
#2 smb_setup_connection (libcurl.so.4)
#3 setup_connection_internals (libcurl.so.4)
#4 url_create_needle (libcurl.so.4)
#5 url_find_or_create_conn (libcurl.so.4)
SUMMARY: AddressSanitizer: heap-use-after-free in __interceptor_strlen
0x502000002a57 is located 7 bytes inside of 13-byte region [0x502000002a50,0x502000002a5d)
How to read this:
- The first line says ASAN caught a heap-use-after-free at a specific address.
READ of size 1means the program tried to read a single byte from that address. - The first stack (the
#0to#13block) is where the bad read happened.__interceptor_strlenis ASAN's wrapper around the standard C functionstrlen, which counts characters until it hits a NUL byte. It was called fromsmb_send_open, which was called fromsmb_request_state, and so on up through the normal transfer machinery (curl_multi_perform,curl_easy_perform,serial_transfers,main). In other words, the read happened during a perfectly ordinary transfer. - The second stack (
freed by thread T0 here) is where the memory was freed.smb_conn_dtoris the SMB connection destructor. It was reached throughCurl_conn_free, which was called byurl_find_or_create_conn, the function that looks up or creates a connection. So the free happened during the connection reuse lookup. - The third stack (
previously allocated by thread T0 here) is where the memory was originally allocated.smb_parse_url_pathcalledstrdup(which duplicates a string into fresh memory), and that happened when the connection was first set up (smb_setup_connection). - The last line is the clincher: the faulting address sits 7 bytes inside a 13-byte region. That matches exactly the offset of the file part inside the duplicated path:
share2/file2is 13 bytes, andfile2starts 7 bytes in.
The three stacks tell the whole story. The read happens in strlen called from smb_send_open, reached through smb_request_state and the normal multi/easy transfer path. The free happens in smb_conn_dtor, reached from Curl_conn_free called by url_find_or_create_conn, that is, during the connection reuse lookup. The allocation happened in smb_parse_url_path, called from smb_setup_connection when the connection was first set up. The faulting address sits 7 bytes inside a 13-byte region, which matches the offset of the file part inside the duplicated path.
Root cause: why it happens
In smb_parse_url_path() (lib/smb.c, around lines 398 to 435), the path is duplicated into connection-owned memory and then split in place:
smbc->share = strdup(path)allocates"share2/file2", 13 bytes.- The
/is replaced with\0, splitting the buffer into"share2\0file2\0". req->path = slashpoints 7 bytes intosmbc->share, at the start offile2.
So req->path is a borrowed pointer into memory owned by the SMB connection, stored on the easy handle. When the second URL reuses the pooled connection from the first URL:
url_find_or_create_conn()finds a match and frees the needle connection.Curl_conn_free()callssmb_conn_dtor(), which callsfree(smbc->share).req->pathnow dangles into freed heap.
Then smb_request_state() reaches smb_send_open(), which does:
const size_t byte_count = strlen(req->path) + 1; // UAF read
This line asks strlen how long the file path is, so it can size the SMB open message. strlen walks the string byte by byte until it finds a NUL. But the bytes it is walking are no longer owned by curl: they were freed a moment earlier. ASAN catches the first byte read and stops the program.
ASAN confirms the layout: the address is 7 bytes inside a 13-byte region, freed by smb_conn_dtor and previously allocated by smb_parse_url_path via strdup.
The design flaw is the ownership mismatch: the easy handle keeps a pointer into connection-owned memory across a point where the connection can be destroyed. Nothing in the reuse path invalidates or re-derives req->path when the connection it points into is freed, so the dangling pointer survives into the next state machine step.
Impact: what an attacker could do
The report classifies this as a heap-use-after-free (CWE-416) reachable from a simple two-URL curl command line. No authentication to a real SMB server is required: the UAF occurs client-side before any server response to the second request. The immediate result is a guaranteed crash, a denial of service.
The researcher also notes that if the freed 13-byte heap region is reallocated with attacker-influenced data before the read, it could potentially lead to information disclosure or further memory corruption. That part is stated as a possibility, not demonstrated. In plain terms: if an attacker can arrange for the freed memory to be reused by something else before strlen reads it, the program might read data the attacker controls, or misbehave in ways beyond a simple crash. The report does not show this happening; it only points out the door is open.
Fix
The report does not describe a fix or a patch.
Variants to test
These are follow-up experiments to see how far the bug reaches.
- Other protocols with borrowed path pointers. Look for handlers that store a pointer into connection-owned memory on the easy handle and then allow the connection to be freed during reuse. A positive result is an ASAN use-after-free report whose free stack goes through a connection destructor and whose allocation stack goes through the protocol's URL parser.
- More than two URLs. Try three or more SMB URLs to the same host with different shares. A positive result is the same UAF, possibly on a later transfer, showing the bug is not limited to the second URL.
- Mixed hosts and ports. Vary host and port between URLs to see which combinations still hit the reuse path. A positive result is the UAF appearing whenever the pool lookup matches and frees the needle connection.
- Heap grooming before the read. Arrange allocations between the free and the
strlenso the freed region is reused. A positive result is the read returning data from the new allocation rather than crashing immediately, which is the precondition for the information disclosure the report mentions.
Glossary
- AddressSanitizer (ASAN): a compiler tool that detects memory errors such as use-after-free and prints a report with the read, free, and allocation stacks.
- Borrowed pointer: a pointer to memory that another part of the program owns and is responsible for freeing.
- Connection pool: a cache of open network connections that curl reuses for later requests to the same host.
- Crash: an abnormal termination of a program, usually because it touched memory it should not have.
- CWE-416: the standard catalogue number for use-after-free bugs.
- Dangling pointer: a pointer whose target memory has been freed; it still holds the old address but no longer points at anything valid.
- Denial of service (DoS): a bug or attack that stops a program or service from working, often by crashing it.
- Easy handle: in libcurl, the object representing one transfer, holding the URL, options, and per-transfer state.
free(): the C function that hands a block of heap memory back to the system.- Heap: the area of memory a program uses for allocations made at runtime.
- Heap grooming: deliberately arranging allocations so that a freed block gets reused by a specific later allocation.
- libcurl: the library form of curl, embedded in other programs; the command-line tool uses it.
- NUL byte: the byte value zero, used in C to mark the end of a string.
- Pointer: a value that holds a memory address, used to read or write the memory at that address.
- Protocol: an agreed language two computers use to communicate, such as HTTP or SMB.
- SMB (Server Message Block): the file-sharing protocol used on Windows networks.
- Stack trace: a list of function calls showing how the program reached a particular point.
strdup: a C function that duplicates a string into freshly allocated memory.strlen: a C function that counts the bytes in a string until it reaches a NUL byte.- Use-after-free (UAF): a bug where a program reads or writes memory after it has been freed.
- WSL2: Windows Subsystem for Linux, version 2, which lets you run Linux inside Windows.