]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
http: look for trailing 'type=' in ftp:// without strstr
authorDaniel Stenberg <daniel@haxx.se>
Tue, 14 Oct 2025 16:08:27 +0000 (18:08 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 15 Oct 2025 06:02:44 +0000 (08:02 +0200)
- it could find a wrong string
- this is faster

Closes #19065

lib/http.c

index 6b1538a737e918d32470f8ed73a6f3f6ff19e817..850bfaefa684ef68c396a0f022cf010548cea97c 100644 (file)
@@ -2040,27 +2040,26 @@ static CURLcode http_target(struct Curl_easy *data,
     if(result)
       return result;
 
-    if(curl_strequal("ftp", data->state.up.scheme)) {
-      if(data->set.proxy_transfer_mode) {
-        /* when doing ftp, append ;type=<a|i> if not present */
-        char *type = strstr(path, ";type=");
-        if(type && type[6] && type[7] == 0) {
-          switch(Curl_raw_toupper(type[6])) {
-          case 'A':
-          case 'D':
-          case 'I':
-            break;
-          default:
-            type = NULL;
-          }
-        }
-        if(!type) {
-          result = curlx_dyn_addf(r, ";type=%c",
-                                  data->state.prefer_ascii ? 'a' : 'i');
-          if(result)
-            return result;
+    if(curl_strequal("ftp", data->state.up.scheme) &&
+       data->set.proxy_transfer_mode) {
+      /* when doing ftp, append ;type=<a|i> if not present */
+      size_t len = strlen(path);
+      bool type_present = FALSE;
+      if((len >= 7) && !memcmp(&path[len - 7], ";type=", 6)) {
+        switch(Curl_raw_toupper(path[len - 1])) {
+        case 'A':
+        case 'D':
+        case 'I':
+          type_present = TRUE;
+          break;
         }
       }
+      if(!type_present) {
+        result = curlx_dyn_addf(r, ";type=%c",
+                                data->state.prefer_ascii ? 'a' : 'i');
+        if(result)
+          return result;
+      }
     }
   }