]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
urlapi: when URL encoding the fragment, pass in the right length
authorDaniel Stenberg <daniel@haxx.se>
Thu, 2 Nov 2023 12:43:54 +0000 (13:43 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 2 Nov 2023 15:23:17 +0000 (16:23 +0100)
A benign bug because it would only add an extra null terminator.

Made lib1560 get a test that runs this code.

Closes #12250

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

index 329f80393b75ea2e79834bd21f8f628ef37dcfd3..032859f88daa660a466069e924cab942eceb0309 100644 (file)
@@ -1224,7 +1224,7 @@ static CURLUcode parseurl(const char *url, CURLU *u, unsigned int flags)
       if(flags & CURLU_URLENCODE) {
         struct dynbuf enc;
         Curl_dyn_init(&enc, CURL_MAX_INPUT_LENGTH);
-        if(urlencode_str(&enc, fragment + 1, fraglen, TRUE, FALSE)) {
+        if(urlencode_str(&enc, fragment + 1, fraglen - 1, TRUE, FALSE)) {
           result = CURLUE_OUT_OF_MEMORY;
           goto fail;
         }
index 9d97cbd0653d19114e64116685c0a4b20e210d71..5f11c48552319dc41429736aae03ed7cace2f7e5 100644 (file)
@@ -151,6 +151,9 @@ struct clearurlcase {
 };
 
 static const struct testcase get_parts_list[] ={
+  {"https://curl.se/#  ",
+   "https | [11] | [12] | [13] | curl.se | [15] | / | [16] | %20%20",
+   CURLU_URLENCODE|CURLU_ALLOW_SPACE, 0, CURLUE_OK},
   {"", "", 0, 0, CURLUE_MALFORMED_INPUT},
   {" ", "", 0, 0, CURLUE_MALFORMED_INPUT},
   {"1h://example.net", "", 0, 0, CURLUE_BAD_SCHEME},