]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tool_urlglob: acknowledge OOM in peek_ipv6
authorDaniel Stenberg <daniel@haxx.se>
Mon, 1 Dec 2025 12:14:17 +0000 (13:14 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 1 Dec 2025 13:44:41 +0000 (14:44 +0100)
Previously, an OOM error would just imply not an IPv6 address.

Closes #19784

src/tool_urlglob.c

index 9ea8a274fa0d0518fb0a36a920c874579434073e..bfa54ab8275bbff4895d0e1fb5f79b8d50785cd0 100644 (file)
@@ -343,7 +343,7 @@ static CURLcode glob_range(struct URLGlob *glob, const char **patternp,
 
 #define MAX_IP6LEN 128
 
-static bool peek_ipv6(const char *str, size_t *skip)
+static CURLcode peek_ipv6(const char *str, size_t *skip, bool *ipv6p)
 {
   /*
    * Scan for a potential IPv6 literal.
@@ -355,27 +355,33 @@ static bool peek_ipv6(const char *str, size_t *skip)
   char *endbr = strchr(str, ']');
   size_t hlen;
   CURLUcode rc;
+  CURLcode result = CURLE_OK;
+  *ipv6p = FALSE; /* default to nope */
+  *skip = 0;
   if(!endbr)
-    return FALSE;
+    return CURLE_OK;
 
   hlen = endbr - str + 1;
   if(hlen >= MAX_IP6LEN)
-    return FALSE;
+    return CURLE_OK;
 
   u = curl_url();
   if(!u)
-    return FALSE;
+    return CURLE_OUT_OF_MEMORY;
 
   memcpy(hostname, str, hlen);
   hostname[hlen] = 0;
 
   /* ask to "guess scheme" as then it works without an https:// prefix */
   rc = curl_url_set(u, CURLUPART_URL, hostname, CURLU_GUESS_SCHEME);
-
   curl_url_cleanup(u);
-  if(!rc)
+  if(rc == CURLUE_OUT_OF_MEMORY)
+    return CURLE_OUT_OF_MEMORY;
+  if(!rc) {
     *skip = hlen;
-  return rc ? FALSE : TRUE;
+    *ipv6p = TRUE;
+  }
+  return result;
 }
 
 static CURLcode add_glob(struct URLGlob *glob, size_t pos)
@@ -414,7 +420,11 @@ static CURLcode glob_parse(struct URLGlob *glob, const char *pattern,
       if(*pattern == '[') {
         /* skip over IPv6 literals and [] */
         size_t skip = 0;
-        if(!peek_ipv6(pattern, &skip) && (pattern[1] == ']'))
+        bool ipv6;
+        res = peek_ipv6(pattern, &skip, &ipv6);
+        if(res)
+          return res;
+        if(!ipv6 && (pattern[1] == ']'))
           skip = 2;
         if(skip) {
           if(curlx_dyn_addn(&glob->buf, pattern, skip))