]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
urlapi: make parse_file() return zero data on error
authorDaniel Stenberg <daniel@haxx.se>
Wed, 15 Apr 2026 07:47:00 +0000 (09:47 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 15 Apr 2026 08:14:09 +0000 (10:14 +0200)
This fixes the torture failures in 1675

Also, make it allocate the scheme *after* the path has been verified, so
that it is avoided in the common error cases.

Fixes #21326
Closes #21324

lib/urlapi.c

index a3036dcf6afc39d4ac588ba055e5378d45ba3e2e..9553d9990c9acbd5d014c1a27d5d366e4b058bd5 100644 (file)
@@ -844,6 +844,9 @@ UNITTEST CURLUcode parse_file(const char *url, size_t urllen, CURLU *u,
 {
   const char *path;
   size_t pathlen;
+
+  *pathp = NULL;
+  *pathlenp = 0;
   if(urllen <= 6)
     /* file:/ is not enough to actually be a complete file: URL */
     return CURLUE_BAD_FILE_URL;
@@ -852,10 +855,6 @@ UNITTEST CURLUcode parse_file(const char *url, size_t urllen, CURLU *u,
   path = &url[5];
   pathlen = urllen - 5;
 
-  u->scheme = curlx_strdup("file");
-  if(!u->scheme)
-    return CURLUE_OUT_OF_MEMORY;
-
   /* Extra handling URLs with an authority component (i.e. that start with
    * "file://")
    *
@@ -915,6 +914,10 @@ UNITTEST CURLUcode parse_file(const char *url, size_t urllen, CURLU *u,
     pathlen--;
   }
 #endif
+  u->scheme = curlx_strdup("file");
+  if(!u->scheme)
+    return CURLUE_OUT_OF_MEMORY;
+
   *pathp = path;
   *pathlenp = pathlen;
   return CURLUE_OK;