Skip to content
Memory corruption Disclosed report Intermediate

heap-buffer-overflow (buffer read overrun) in curl: ourWriteOut() src/tool_writeout.c:115

A heap buffer over-read in curl's --write-out option occurs when a format string ends with a percent sign, causing the code to skip the terminating null byte and read past the allocated buffer. An attacker could potentially cause curl to display memory contents, such as passwords or secret keys, in the output.

geeknik Follow

Originally disclosed on HackerOne

  • Fixed in 9 months
  • Disclosed after 14 months

Curl is a ubiquitous tool in use by millions of people around the world. I reported this flaw to the curl security mailing list on 10 March 2017:

./curl -q -K test000
==21754==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000dbb2 at pc 0x0000004fcd39 bp 0x7ffcd27dc250 sp 0x7ffcd27dc248
READ of size 1 at 0x60200000dbb2 thread T0
    #0 0x4fcd38 in ourWriteOut /root/curl/src/tool_writeout.c:115:3
    #1 0x4ec947 in operate_do /root/curl/src/tool_operate.c:1669:11
    #2 0x4e053e in operate /root/curl/src/tool_operate.c:2024:20
    #3 0x4de5a6 in main /root/curl/src/tool_main.c:252:14
    #4 0x7fad0a96fb44 in __libc_start_main /build/glibc-qK83Be/glibc-2.19/csu/libc-start.c:287
    #5 0x4c407c in _start (/root/curl/src/curl+0x4c407c)

0x60200000dbb2 is located 0 bytes to the right of 2-byte region [0x60200000dbb0,0x60200000dbb2)
allocated by thread T0 here:
    #0 0x4a69fb in malloc (/root/curl/src/curl+0x4a69fb)
    #1 0x7fad0a9cf989 in __strdup /build/glibc-qK83Be/glibc-2.19/string/strdup.c:42

SUMMARY: AddressSanitizer: heap-buffer-overflow /root/curl/src/tool_writeout.c:115 ourWriteOut

Fixed by the developers on 12 March 2017: https://github.com/curl/curl/commit/1890d59905414ab84a35892b2e45833654aa5c13

From the git commit:

If a % ended the statement, the string's trailing NUL would be skipped
and memory past the end of the buffer would be accessed and potentially
displayed as part of the --write-out output.

From the curl security mailing list:

It's possible that the data past the end of the buffer could get displayed as
part of the --write-out output (up to the first nul character, anyway), so
theoretically, it could write out a password or secret key or something.

The original report as published on HackerOne, by geeknik. 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 failed to handle a trailing percent sign in the --write-out format string, skipping the null terminator and reading past the buffer.

Impact

Theoretically, data past the buffer could be displayed, potentially exposing a password or secret key.

What the attacker needed

Ability to set --write-out format string; format string ends with %

The fix

The developers fixed the issue in a commit on 12 March 2017.

How it was found

  1. Run curl with a configuration file that sets a --write-out format string ending with a percent sign.
  2. Observe the heap-buffer-overflow error under AddressSanitizer.

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 command-line tool for transferring data. The --write-out option lets you print custom information after a transfer. If the format string ends with a percent sign, curl mistakenly reads beyond the end of a memory buffer and may print whatever data follows, which could include sensitive information.

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 by geeknik

View all

79 more disclosed reports, best first.

More from Internet Bug Bounty

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.