Skip to content
Memory corruption Disclosed report Advanced CVE-2019-5435CVE-2018-14618

CVE-2019-5435: An integer overflow found in /lib/urlapi.c

An integer overflow in libcurl's URL parsing function can occur when a URL longer than 2GB is processed on a 32-bit system, leading to a heap buffer overrun. An attacker could trigger this by supplying an extremely long URL to curl_url_set, potentially causing a crash or other impact.

1wc Follow

Originally disclosed on HackerOne

  • Triaged in under an hour
  • Fixed in 28 days
  • Paid in 11 days
  • Disclosed after 19 months

Summary:

libcurl contains a heap-based buffer overrun in /lib/urlapi.c. A similiar issue to CVE-2018-14618.

Steps To Reproduce:

analysis

I found a potential integer overflow which may lead to a buffer overrun in /curl/lib/urlapi.c. In function seturl, urllen was multiplied by 2 and then passed to malloc. So an integer overflow will happen when the url is as long as 2GB in a 32 bit OS.

C
static CURLUcode seturl(const char *url, CURLU *u, unsigned int flags)
{
  char *path;
  bool path_alloced = FALSE;
  char *hostname;
  char *query = NULL;
  char *fragment = NULL;
  CURLUcode result;
  bool url_has_scheme = FALSE;
  char schemebuf[MAX_SCHEME_LEN];
  char *schemep = NULL;
  size_t schemelen = 0;
  size_t urllen;
  const struct Curl_handler *h = NULL;

  if(!url)
    return CURLUE_MALFORMED_INPUT;

  /*************************************************************
   * Parse the URL.
   ************************************************************/
  /* allocate scratch area */
  urllen = strlen(url);
  path = u->scratch = malloc(urllen * 2 + 2); <= overflow here

The url was passed by parseurl to seturl.

C
static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags)
{
  CURLUcode result = seturl(url, u, flags);
  if(result) {
    free_urlhandle(u);
    memset(u, 0, sizeof(struct Curl_URL));
  }
  return result;
}

And the parseurl was called when do curl_url_set and execute the parse of url. If someone use libcurl to code, and call curl_url_set with a extreme long url, it might be triggered.

CURLUcode curl_url_set(CURLU *u, CURLUPart what,
                       const char *part, unsigned int flags)
......
case CURLUPART_URL: {
    /*
     * Allow a new URL to replace the existing (if any) contents.
     *
     * If the existing contents is enough for a URL, allow a relative URL to
     * replace it.
     */
    CURLUcode result;
    char *oldurl;
    char *redired_url;
    CURLU *handle2;

    if(Curl_is_absolute_url(part, NULL, MAX_SCHEME_LEN)) {
      handle2 = curl_url();
      if(!handle2)
        return CURLUE_OUT_OF_MEMORY;
      result = parseurl(part, handle2, flags); <= call parseurl
      if(!result)
        mv_urlhandle(handle2, u);
      else
        curl_url_cleanup(handle2);
      return result;
    }

Impact

It might leads to a crash or some other impact.

The original report as published on HackerOne, by 1wc. 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 multiplication of the URL length by 2 in the malloc call can overflow on 32-bit systems, resulting in an undersized buffer allocation.

Impact

It might lead to a crash or some other impact.

What the attacker needed

32-bit system; URL longer than 2GB; application uses libcurl's URL API

How it was found

  1. Call curl_url_set with a URL longer than 2GB on a 32-bit system.
  2. The URL is passed to parseurl, which calls seturl.
  3. In seturl, urllen * 2 overflows, leading to a small malloc allocation.
  4. The undersized allocation can lead to a heap buffer overrun.

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 stores a very long piece of text, it first calculates how much memory to reserve. If that calculation overflows (like a car odometer rolling over), the program reserves too little memory and then writes past the end, corrupting data. Here, a URL longer than 2 gigabytes on a 32-bit system causes this overflow, which could 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.