Skip to content
Memory corruption Disclosed report Advanced

Integer overlow in "header_append" function

The header_append function in libcurl adds a user-controlled length to the current header buffer size without checking for integer overflow, so the size check can be bypassed and a subsequent memcpy writes beyond the heap buffer. An attacker could potentially achieve remote code execution, though no proof of concept is provided.

invictus1306 Follow

Originally disclosed on HackerOne

  • Disclosed after 20 months

Summary:

The function header_append contains an integer overflow, it can bypass the check on the length and can lead to a subsequent heap buffer overflow.

Steps To Reproduce:

I don't have PoC, but here there is a little description of the problem (vulnerable code)

static CURLcode header_append(struct Curl_easy *data,
                              struct SingleRequest *k,
                              size_t length)
{
  size_t newsize = k->hbuflen + length; // <-- here there is the point of the integer overflow (length is user controllable)
// the value of "newsize" will be small and minor than CURL_MAX_HTTP_HEADER
  if(newsize > CURL_MAX_HTTP_HEADER) {
    /* The reason to have a max limit for this is to avoid the risk of a bad
       server feeding libcurl with a never-ending header that will cause
       reallocs infinitely */
    failf(data, "Rejected %zu bytes header (max is %d)!", newsize,
          CURL_MAX_HTTP_HEADER);
    return CURLE_OUT_OF_MEMORY;
  }
...
// here the length is a big number, and it can lead in a heap overflow
  memcpy(k->hbufp, k->str_start, length);
  k->hbufp += length;
  k->hbuflen += length;
  *k->hbufp = 0;

  return CURLE_OK;
}

Additional info

As I mentioned I don't have a PoC, but I saw that this function could be reached in different ways e.g., evil server, by running curl with a specific argument (extend the header size), curl API (but not sure).

Impact

  • It can lead on a RCE

The original report as published on HackerOne, by invictus1306. 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 addition of k->hbuflen and length can overflow size_t, making newsize small enough to pass the CURL_MAX_HTTP_HEADER check before a memcpy uses the original large length.

Impact

It could lead to remote code execution, but the report provides no proof of concept and only suggests possible reachability via an evil server or specific curl arguments.

What the attacker needed

No PoC provided; attacker controls header length; reachable via evil server or curl argument

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 receives data, it often stores it in a temporary memory area. If the program miscalculates how much space is needed, it can write past the end of that area, corrupting other data. Here, a very large number causes the size calculation to wrap around to a small value, so the safety check passes and the program then copies too much data into a small buffer.

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.