Uncontrolled File Write/Arbitrary File Creation
The dumpeasysrc function in curl passes the user-supplied --libcurl output path straight to fopen without any validation, so the tool will write generated C source to whatever file the user names. An attacker who can influence that path could overwrite files the running user has write access to, corrupting their contents.
- Disclosed after under an hour
Description
The dumpeasysrc function in the provided code snippet allows an attacker to specify an arbitrary file path for outputting the generated libcurl source code via the global->libcurl variable. If the global->libcurl value is not properly sanitized or restricted, a malicious user could provide a path to a sensitive system file (e.g., /etc/passwd, /etc/cron.d/malicious_job, user's .bashrc, etc.) or a device file (e.g., /dev/null, /dev/random).
The core issue is that fopen(o, FOPEN_WRITETEXT) is called directly with o = global->libcurl without any checks on the path provided.
Vulnerable code
void dumpeasysrc(struct GlobalConfig *global)
{
struct curl_slist *ptr;
char *o = global->libcurl; // <--- 'o' holds the user-supplied file path
FILE *out;
bool fopened = FALSE;
if(strcmp(o, "-")) {
out = fopen(o, FOPEN_WRITETEXT); // <--- Direct use of user-supplied path in fopen()
fopened = TRUE;
}
else
out = stdout;
// ... rest of the function writes data to 'out'
}
Proof of Concept (POC) to Prove Real Vulnerability and Step-by-Step
I will demonstrate overwriting a user-created, non-critical file within a standard temporary directory. This is easily reproducible and clearly shows the integrity impact without attempting to directly compromise critical system files, which might be blocked by OS permissions for a regular user.
- Create a distinctive, dummy file in a temporary location:
echo "This is the ORIGINAL content of the file." > /tmp/curl_test_overwrite.txt
ls -l /tmp/curl_test_overwrite.txt
cat /tmp/curl_test_overwrite.txt

- Execute the vulnerable curl command to overwrite the file:
Assuming your curl executable (the one you built with the vulnerable code) is accessible in your PATH or you're running it with ./curl.
#Curl Version
└─# ./curl -V
WARNING: this libcurl is Debug-enabled, do not use in production
curl 8.15.0-DEV (x86_64-pc-linux-gnu) libcurl/8.15.0-DEV zlib/1.3.1 libpsl/0.21.2
Release-Date: [unreleased]
Protocols: dict file ftp gopher http imap ipfs ipns mqtt pop3 rtsp smtp telnet tftp ws
Features: alt-svc AsynchDNS Debug IPv6 Largefile libz PSL threadsafe TrackMemory UnixSockets
./curl --libcurl /tmp/curl_test_overwrite.txt http://example.com

Using http://example.com is better than google.com as it avoids potential redirects and makes the curl output simpler, focusing on the --libcurl aspect.
- Verify the content of the file after the curl execution:
cat /tmp/curl_test_overwrite.txt
The content of /tmp/curl_test_overwrite.txt will be replaced by the generated libcurl C code. It will look something like this:

Impact
Data Corruption/Loss: Arbitrary files can be overwritten with the generated libcurl C source code.
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 output path from the --libcurl option is used directly in fopen with no validation, so any writable path is accepted.
Impact
Files the user can write to could be overwritten with generated C source, causing data corruption or loss; the report does not show compromise of files the user cannot write.
What the attacker needed
Local access to run curl; user can write to the target file
How it was found
- Create a dummy file in a temporary directory and note its original contents.
- Run the vulnerable curl build with the --libcurl option pointed at that file and a simple URL.
- Read the file again and observe that its contents were replaced by generated C code.
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.
The report says curl does not check the file name, so it could overwrite any file the user can write to with that generated code.
What is File upload?
An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.