]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
url: bad CURLOPT_CONNECT_TO syntax now returns error
authorAlexis Vachette <alexis@unhu.fr>
Thu, 3 Jun 2021 12:49:49 +0000 (14:49 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 4 Jun 2021 12:08:30 +0000 (14:08 +0200)
Added test 3020 to verify

Closes #7183

lib/url.c
tests/data/Makefile.inc
tests/data/test3020 [new file with mode: 0644]

index edcdf54b1a07e17f3d3d76503bcb186f05f6bf6f..84d37a560eaf55cb696f2ed256c7af1c9f1b9bb2 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -2995,6 +2995,7 @@ static CURLcode parse_connect_to_host_port(struct Curl_easy *data,
   char *host_portno;
   char *portptr;
   int port = -1;
+  CURLcode result = CURLE_OK;
 
 #if defined(CURL_DISABLE_VERBOSE_STRINGS)
   (void) data;
@@ -3043,8 +3044,8 @@ static CURLcode parse_connect_to_host_port(struct Curl_easy *data,
      */
 #else
     failf(data, "Use of IPv6 in *_CONNECT_TO without IPv6 support built-in!");
-    free(host_dup);
-    return CURLE_NOT_BUILT_IN;
+    result = CURLE_NOT_BUILT_IN;
+    goto error;
 #endif
   }
 
@@ -3057,10 +3058,12 @@ static CURLcode parse_connect_to_host_port(struct Curl_easy *data,
     if(*host_portno) {
       long portparse = strtol(host_portno, &endp, 10);
       if((endp && *endp) || (portparse < 0) || (portparse > 65535)) {
-        infof(data, "No valid port number in connect to host string (%s)\n",
+        failf(data, "No valid port number in connect to host string (%s)",
               host_portno);
         hostptr = NULL;
         port = -1;
+        result = CURLE_SETOPT_OPTION_SYNTAX;
+        goto error;
       }
       else
         port = (int)portparse; /* we know it will fit */
@@ -3071,15 +3074,16 @@ static CURLcode parse_connect_to_host_port(struct Curl_easy *data,
   if(hostptr) {
     *hostname_result = strdup(hostptr);
     if(!*hostname_result) {
-      free(host_dup);
-      return CURLE_OUT_OF_MEMORY;
+      result = CURLE_OUT_OF_MEMORY;
+      goto error;
     }
   }
 
   *port_result = port;
 
+  error:
   free(host_dup);
-  return CURLE_OK;
+  return result;
 }
 
 /*
index 8f98d0b20b8f68a433ed95ad9eb27f1182b606ef..78ec645b7ce03802b5e1c7643880e5c98f3aa074 100644 (file)
@@ -232,8 +232,4 @@ test2100 \
 \
 test3000 test3001 test3002 test3003 test3004 test3005 test3006 test3007 \
 test3008 test3009 test3010 test3011 test3012 test3013 test3014 test3015 \
-test3016 \
-\
-test3017 test3018 \
-\
-test3019
+test3016 test3017 test3018 test3019 test3020 \
diff --git a/tests/data/test3020 b/tests/data/test3020
new file mode 100644 (file)
index 0000000..25bf6dd
--- /dev/null
@@ -0,0 +1,36 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+--connect-to
+</keywords>
+</info>
+
+#
+# Server-side
+<reply>
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+http
+</server>
+<name>
+HTTP with invalid --connect-to syntax
+</name>
+<command>
+--connect-to ::example.com:example.com http://example.com:%HTTPPORT/%TESTNUMBER
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<errorcode>
+49
+</errorcode>
+</verify>
+</testcase>