From c60d90cd65391f862b094c4720496b285201dd7f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 15 Apr 2026 09:47:00 +0200 Subject: [PATCH] urlapi: make parse_file() return zero data on error 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 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/urlapi.c b/lib/urlapi.c index a3036dcf6a..9553d9990c 100644 --- a/lib/urlapi.c +++ b/lib/urlapi.c @@ -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;