]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_cb_hdr: add an additional parsing check
authorJay Satiro <raysatiro@yahoo.com>
Tue, 14 Nov 2023 06:19:14 +0000 (01:19 -0500)
committerJay Satiro <raysatiro@yahoo.com>
Tue, 14 Nov 2023 09:14:01 +0000 (04:14 -0500)
- Don't dereference the past-the-end element when parsing the server's
  Content-disposition header.

As 'p' is advanced it can point to the past-the-end element and prior
to this change 'p' could be dereferenced in that case.

Technically the past-the-end element is not out of bounds because dynbuf
(which manages the header line) automatically adds a null terminator to
every buffer and that is not included in the buffer length passed to
the header callback.

Closes https://github.com/curl/curl/pull/12320

src/tool_cb_hdr.c

index df44f7aa73ce3c1f34723bf6c6599feb42592c54..a310e398467b2b4dc78d6ae45ef65861812f7818 100644 (file)
@@ -150,16 +150,19 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
       char *filename;
       size_t len;
 
-      while(*p && (p < end) && !ISALPHA(*p))
+      while((p < end) && *p && !ISALPHA(*p))
         p++;
       if(p > end - 9)
         break;
 
       if(memcmp(p, "filename=", 9)) {
         /* no match, find next parameter */
-        while((p < end) && (*p != ';'))
+        while((p < end) && *p && (*p != ';'))
           p++;
-        continue;
+        if((p < end) && *p)
+          continue;
+        else
+          break;
       }
       p += 9;