Skip to content
Memory corruption Disclosed report Intermediate

Integer Underflow in src/var.c

The setvariable function in curl's src/var.c calculates a length by subtracting startoffset from endoffset without checking that startoffset is not greater than endoffset. This can produce a huge size_t value, leading to heap buffer overflow or denial of service when passed to addvariable.

f_i_h Follow

Originally disclosed on HackerOne

  • Disclosed after 32 hours

Summary:

A potential Integer Underflow vulnerability was identified in the setvariable function within src/var.c. the flaw occurs during the calculation of the variable content length (clen) when a byte range is specified. specifically, the code fails to validate if startoffset is greater than endoffset before performing subtraction, leading to a massive wrapped-around value when cast to size_t. This leads to an inconsistent state where clen holds an impossibly large value, causing memory corruption when passed to downstream functions

URL : https://github.com/curl/curl/blob/master/src/var.c#L375

function: setvariable() file : src/var.c:480 clen = (size_t)(endoffset - startoffset) + 1;

Proof of Concept using a debugger (GDB) to simulate the logic bypass: set a breakpoint at setvariable Manipulate the offsets:set var startoffset = 100 set var endoffset = 50

Result: clen as size_t: 18446744073709551567

image.png
image.png From the original on HackerOne

Workarounds Add a sanity check to ensure startoffset does not exceed endoffset before calculation

Impact

This massive clen value is subsequently passed to addvariable(), where it is used as a length parameter for memory operations. this can lead to:

Heap Buffer Overflow: attempting to copy data using an invalid length

Denial of Service : triggering an out-of-memory condition or a crash

The original report as published on HackerOne, by f_i_h. 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

Likely, the code does not validate that startoffset is less than or equal to endoffset before subtracting them, causing an integer underflow when startoffset is greater.

Impact

This could lead to a heap buffer overflow or denial of service (out-of-memory or crash) when the huge length is used in memory operations.

What the attacker needed

Debugger access to manipulate variables

The fix

A sanity check should be added to ensure startoffset does not exceed endoffset before the calculation.

How it was found

  1. Set a breakpoint at the setvariable function in a debugger.
  2. Manipulate the offsets so that startoffset is 100 and endoffset is 50.
  3. Observe that clen becomes a very large size_t value.

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.

In programming, when you subtract a larger number from a smaller one using unsigned integers, the result wraps around to a very large number. Here, the code calculates a length without checking that the start is before the end, so it gets an enormous length. That huge length is then used to copy data, which can overflow memory and crash the program.

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.