]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
urlapi: reject short file URLs
authorDaniel Stenberg <daniel@haxx.se>
Mon, 22 Nov 2021 09:11:59 +0000 (10:11 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 23 Nov 2021 07:45:21 +0000 (08:45 +0100)
file URLs that are 6 bytes or shorter are not complete. Return
CURLUE_MALFORMED_INPUT for those. Extended test 1560 to verify.

Triggered by #8041
Closes #8042

lib/urlapi.c
tests/libtest/lib1560.c

index b0bce2e7d9c7eed8ae4c447de2d67f7d2b062225..ff157c743dbfd5e180d0a4940b19657ba091dffe 100644 (file)
@@ -824,6 +824,10 @@ static CURLUcode seturl(const char *url, CURLU *u, unsigned int flags)
 
   /* handle the file: scheme */
   if(url_has_scheme && !strcmp(schemebuf, "file")) {
+    if(urllen <= 6)
+      /* file:/ is not enough to actually be a complete file: URL */
+      return CURLUE_MALFORMED_INPUT;
+
     /* path has been allocated large enough to hold this */
     strcpy(path, &url[5]);
 
index de3e3109de8b49a2357e62821be537021d105642..1cc1a60ec8be63b76ec43c0433ab137482712396 100644 (file)
@@ -267,6 +267,12 @@ static const struct testcase get_parts_list[] ={
   {"file:/hello.html",
    "file | [11] | [12] | [13] | [14] | [15] | /hello.html | [16] | [17]",
    0, 0, CURLUE_OK},
+  {"file:/h",
+   "file | [11] | [12] | [13] | [14] | [15] | /h | [16] | [17]",
+   0, 0, CURLUE_OK},
+  {"file:/",
+   "file | [11] | [12] | [13] | [14] | [15] | | [16] | [17]",
+   0, 0, CURLUE_MALFORMED_INPUT},
   {"file://127.0.0.1/hello.html",
    "file | [11] | [12] | [13] | [14] | [15] | /hello.html | [16] | [17]",
    0, 0, CURLUE_OK},