Skip to content
Memory corruption Disclosed report Intermediate

Heap-buffer-overflow (Out-of-Bounds Read) in DoH hostname encoding

An out-of-bounds read occurs in curl's DNS-over-HTTPS hostname encoding when the hostname is an empty string, because the code accesses the byte before the buffer. An attacker who can supply such a hostname could cause a crash, and the report suggests possible arbitrary code execution.

reporascal_1 Follow

Originally disclosed on HackerOne

Informational View original
  • Disclosed after 35 hours

Summary: I found a heap-buffer-overflow in the doh_req_encode function in lib/doh.c.

The bug happens when curl processes a DNS-over-HTTPS request for a hostname that is an empty string. The code gets the string length as 0, then tries to access host[len - 1], which becomes host[-1]. This is an out-of-bounds read. It reads memory just before the allocated buffer.


Steps to Reproduce:

  1. Compile curl with AddressSanitizer.

    Bash

autoreconf -fi CFLAGS="-g -fsanitize=address" ./configure --with-openssl make ```

  1. Run this simple command. The arguments 0 and '‌' cause curl to process an empty string hostname.

    Bash
    ./src/curl 0 --doh-url 0 '‌'
    
  2. The program will crash and you'll see the ASan report.

==2649804==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7c1ff51e756f at pc 0x5555556dd998 bp 0x7fffffffc9c0 sp 0x7fffffffc9b0 READ of size 1 at 0x7c1ff51e756f thread T0 #0 0x5555556dd997 in doh_req_encode /home/anuja/curl1/curl/lib/doh.c:115 #1 0x5555556dd997 in doh_probe_run /home/anuja/curl1/curl/lib/doh.c:306 #2 0x5555556de35b in Curl_doh /home/anuja/curl1/curl/lib/doh.c:487 #3 0x55555561f0ee in Curl_resolv /home/anuja/curl1/curl/lib/hostip.c:923 #4 0x55555567ae1c in resolve_server /home/anuja/curl1/curl/lib/url.c:3305


## Impact

Crash or, potentially,  arbitrary code execution.

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

Impact

The bug causes a crash and could potentially lead to arbitrary code execution.

What the attacker needed

Curl built with DoH support; ability to supply an empty hostname

How it was found

  1. Compile curl with AddressSanitizer enabled.
  2. Run curl with arguments that make it process an empty string hostname.
  3. Observe the AddressSanitizer heap-buffer-overflow report.

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.

A program stores a hostname in a block of memory and reads the character just before it when the hostname is empty. That memory is outside the block, so the program may crash. The report shows this happening in curl's DNS-over-HTTPS code.

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.