Skip to content
Memory corruption Disclosed report Intermediate

Buffer over-read,, Missing NUL termination in addvariable() causes undefined behavior

The addvariable() function in curl allocates memory for a variable name without space for a null terminator and copies the name without adding one. Later functions call strlen() on this name, causing an out-of-bounds read that can crash the program or potentially leak memory.

sagorhawlader Follow

Originally disclosed on HackerOne

  • Disclosed after 19 hours

Summary:

[In addvariable() (used by setvariable()), the code allocates memory for p->name without space for a null-terminator and copies nlen bytes directly. Later, functions like varcontent() call strlen() on this name, assuming it is null-terminated. This can lead to out-of-bounds memory reads, causing crashes (DoS) or potential information leakage, depending on the runtime context. The issue affects curl’s variable management code and can be triggered via normal usage of --variable or internal API calls.]

[No AI assistance was used to find this issue or generate this report.]

#source file https://github.com/curl/curl/blob/master/src/var.c #issue code ( p = calloc(1, sizeof(struct tool_var) + nlen); if(p) { memcpy(p->name, name, nlen);)

Steps To Reproduce:

  1. [Clone the repo and enter it]

git clone https://github.com/curl/curl.git cd curl CFLAGS="-fsanitize=address,undefined -g -O1" ./configure make -j$(nproc)

  1. [Add a variable via setvariable() (e.g., "TESTVAR=value").]
  2. [Lookup the variable using varcontent() or varexpand().]
  3. [Observe crash or out-of-bounds read via ASAN/UBSAN logs]

#issue code picture location with image #F4950584

Impact

addvariable() fails to NUL‑terminate stored variable names, so subsequent calls to strlen() can read past the allocated buffer and cause an immediate program crash. This results in an availability impact (easy DoS if the code path is reachable), and the out‑of‑bounds read may also expose adjacent memory, creating a potential confidentiality issue. While this bug alone is unlikely to enable remote code execution, it increases overall exploitability when combined with other vulnerabilities. Triage severity should be considered Medium, escalating to High if an information leak can be demonstrated.

Attachments

Screenshot_2025-10-30_100009.png
Screenshot_2025-10-30_100009.png From the original on HackerOne

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

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The code allocates memory for the variable name without an extra byte for a null terminator and copies the name without adding one, so later string functions read beyond the buffer.

Impact

The out-of-bounds read can cause an immediate program crash, leading to a denial of service, and may also expose adjacent memory, creating a potential confidentiality issue; remote code execution is unlikely from this bug alone.

What the attacker needed

Ability to set a variable via --variable or API

How it was found

  1. Clone the curl repository and build it with address and undefined behaviour sanitizers enabled.
  2. Add a variable using setvariable() with a name and value.
  3. Look up the variable using varcontent() or varexpand().
  4. Observe a crash or out-of-bounds read in the sanitizer logs.

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.

When a program stores text, it usually marks the end with a special zero byte called a null terminator. Here, the code forgot to add that zero byte, so when another part of the program tries to measure the text's length, it keeps reading past the end of the memory buffer. This can make the program crash or accidentally reveal nearby memory contents.

What is Memory corruption?

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

More 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.