]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl_url_set: enforce the max string length check for all parts
authorDaniel Stenberg <daniel@haxx.se>
Thu, 8 Jun 2023 11:40:52 +0000 (13:40 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 8 Jun 2023 21:40:08 +0000 (23:40 +0200)
Update the docs and test 1559 accordingly

Closes #11273

docs/libcurl/curl_url_set.3
lib/urlapi.c
tests/data/test1559

index 435818e8bf70681d536db00ac2e2f9649aefb08d..cffe745e82cc5e47c2f98da28d60de7f9e2da20d 100644 (file)
@@ -188,9 +188,8 @@ Returns a \fICURLUcode\fP error value, which is CURLUE_OK (0) if everything
 went fine. See the \fIlibcurl-errors(3)\fP man page for the full list with
 descriptions.
 
-A URL string passed on to \fIcurl_url_set(3)\fP for the \fBCURLUPART_URL\fP
-part, must be shorter than 8000000 bytes otherwise it returns
-\fBCURLUE_MALFORMED_INPUT\fP (added in 7.65.0).
+The input string passed to \fIcurl_url_set(3)\fP must be shorter than eight
+million bytes. Otherwise this function returns \fBCURLUE_MALFORMED_INPUT\fP.
 
 If this function returns an error, no URL part is set.
 .SH "SEE ALSO"
index 7b2498c40e29ca6db972ce9c4ba03616ff31c648..e0c547605a1a9e2a1d453251a629303224b5c2dc 100644 (file)
@@ -1642,6 +1642,7 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what,
   bool leadingslash = FALSE;
   bool appendquery = FALSE;
   bool equalsencode = FALSE;
+  size_t nalloc;
 
   if(!u)
     return CURLUE_BAD_HANDLE;
@@ -1694,6 +1695,11 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what,
     return CURLUE_OK;
   }
 
+  nalloc = strlen(part);
+  if(nalloc > CURL_MAX_INPUT_LENGTH)
+    /* excessive input length */
+    return CURLUE_MALFORMED_INPUT;
+
   switch(what) {
   case CURLUPART_SCHEME: {
     size_t plen = strlen(part);
@@ -1800,14 +1806,8 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what,
   }
   DEBUGASSERT(storep);
   {
-    const char *newp = part;
-    size_t nalloc = strlen(part);
+    const char *newp;
     struct dynbuf enc;
-
-    if(nalloc > CURL_MAX_INPUT_LENGTH)
-      /* excessive input length */
-      return CURLUE_MALFORMED_INPUT;
-
     Curl_dyn_init(&enc, nalloc * 3 + 1 + leadingslash);
 
     if(leadingslash && (part[0] != '/')) {
index 863a89e5aba886468164b518484552bc679b1b56..c307f6447e4d75b74718a4f657c2b3ae370960ae 100644 (file)
@@ -37,7 +37,7 @@ Set excessive URL lengths
 CURLOPT_URL 10000000 bytes URL == 43
 CURLOPT_POSTFIELDS 10000000 bytes data == 0
 CURLUPART_URL 10000000 bytes URL == 3 (Malformed input to a URL function)
-CURLUPART_SCHEME 10000000 bytes scheme == 27 (Bad scheme)
+CURLUPART_SCHEME 10000000 bytes scheme == 3 (Malformed input to a URL function)
 CURLUPART_USER 10000000 bytes user == 3 (Malformed input to a URL function)
 </stdout>
 </verify>