Skip to content
Memory corruption Disclosed report Intermediate

huge COLUMNS causes progress-bar to buffer overflow

curl's progress-bar feature parses the COLUMNS environment variable and casts a long to int without proper bounds checking, causing a buffer overflow when a very large value is supplied. An attacker who can set environment variables can crash curl, leading to a denial of service.

pendrek Follow

Originally disclosed on HackerOne

  • Disclosed after 19 months

Summary:

If an attacker can set environmental variables, curl will always crash with a buffer overflow when downloading a file – if the --progress-bar argument is set.

Steps To Reproduce:

Just run the following command on a 64-bit Linux system (verified on Ubuntu 19.04).

Bash
# Of course you can set the COLUMNS variable in your `.profile` configuration file instead...
env COLUMNS="9223372032559808515" curl "http://hubblesource.stsci.edu/sources/video/clips/details/images/hale_bopp_2.mpg" -o "./test.mpg"

Output

      23,0%*** buffer overfow detected ***: curl terminated
Aborted (core dumped)

Explanation of the bug The progress-bar feature parses the COLUMNS environment variable. The source code aims to guarantee this value to be above 20. However, on Linux systems this check fails due to a faulty integer cast in tool_cb_prg.c:

C
colp = curlx_getenv("COLUMNS");
if(colp) {
     char *endptr;
     long num = strtol(colp, &endptr, 10);
     // Our value of 9223372032559808515 will be OK!
     if((endptr != colp) && (endptr == colp + strlen(colp)) && (num > 20))
         // BUG! Back to int... 9223372032559808515 becomes 3.
         bar->width = (int)num;

Then on line 181 we have the buffer overflow:

C
    barwidth = bar->width - 7; // HERE we get 3-7 resulting in...
    num = (int) (((double)barwidth) * frac);
    if(num > MAX_BARLENGTH)
      num = MAX_BARLENGTH;
    memset(line, '#', num); // .... a crazy high value here!

Impact

If a server runs curl with the --progress-bar argument set and (intentionally or unintentionally) allows an attacker to set environmental variables, the server could easily become a victim of a DoS attack.

The original report as published on HackerOne, by pendrek. 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 a faulty integer cast: a long value from COLUMNS is cast to int without checking it fits, so a large number becomes a small or negative value, leading to an oversized write.

Impact

If a server runs curl with --progress-bar and allows an attacker to set environment variables, the server could become a victim of a DoS attack.

What the attacker needed

Attacker can set environment variables; curl run with --progress-bar

How it was found

  1. Set the COLUMNS environment variable to a very large number.
  2. Run curl with the --progress-bar option to download a file.
  3. Observe the buffer overflow and crash.

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.

curl is a tool for downloading files. When it shows a progress bar, it reads the COLUMNS setting to decide how wide to draw it. If someone sets COLUMNS to a huge number, curl miscalculates and writes past the end of a memory buffer, which crashes 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.