]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
urldata: make 'use_port' an usigned short
authorDaniel Stenberg <daniel@haxx.se>
Mon, 4 Jul 2022 17:42:40 +0000 (19:42 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 4 Jul 2022 17:42:40 +0000 (19:42 +0200)
... instead of a long. It is already enforced to not attempt to set any
value outside of 16 bits unsigned.

Closes #9099

docs/libcurl/opts/CURLOPT_PORT.3
lib/setopt.c
lib/url.c
lib/urldata.h

index 1d3b74004ce0b2c1d2bbc33824a9ba62ecbe4332..1012bfad37336f278b6328828d40fb5b14b60e92 100644 (file)
@@ -42,8 +42,9 @@ protocol.
 Usually, you just let the URL decide which port to use but this allows the
 application to override that.
 
-While this option accepts a 'long', a port number is usually a 16 bit number
-and therefore using a port number over 65535 will cause a runtime error.
+While this option accepts a 'long', a port number is an unsigned 16 bit number
+and therefore using a port number lower than zero or over 65535 will cause a
+\fBCURLE_BAD_FUNCTION_ARGUMENT\fP error.
 .SH DEFAULT
 By default this is 0 which makes it not used. This also makes port number zero
 impossible to set with this API.
index 0ee2609ee28196892888b4ece2190e4aca0be65b..bb0e700fbcfa22b374083802646327cf774672e4 100644 (file)
@@ -1434,12 +1434,12 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
     break;
   case CURLOPT_PORT:
     /*
-     * The port number to use when getting the URL
+     * The port number to use when getting the URL. 0 disables it.
      */
     arg = va_arg(param, long);
     if((arg < 0) || (arg > 65535))
       return CURLE_BAD_FUNCTION_ARGUMENT;
-    data->set.use_port = arg;
+    data->set.use_port = (unsigned short)arg;
     break;
   case CURLOPT_TIMEOUT:
     /*
index 1114c6c12e376f428d2bb391cfefe76c2d8d78bb..287efd5c1c88afa70a3dab6756391732b970678e 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -2128,7 +2128,7 @@ static CURLcode parseurlandfillconn(struct Curl_easy *data,
     unsigned long port = strtoul(data->state.up.port, NULL, 10);
     conn->port = conn->remote_port =
       (data->set.use_port && data->state.allow_port) ?
-      (int)data->set.use_port : curlx_ultous(port);
+      data->set.use_port : curlx_ultous(port);
   }
 
   (void)curl_url_get(uh, CURLUPART_QUERY, &data->state.up.query, 0);
@@ -2964,7 +2964,7 @@ static CURLcode parse_remote_port(struct Curl_easy *data,
     /* if set, we use this instead of the port possibly given in the URL */
     char portbuf[16];
     CURLUcode uc;
-    conn->remote_port = (unsigned short)data->set.use_port;
+    conn->remote_port = data->set.use_port;
     msnprintf(portbuf, sizeof(portbuf), "%d", conn->remote_port);
     uc = curl_url_set(data->state.uh, CURLUPART_PORT, portbuf, 0);
     if(uc)
index 6523d74612d5949bfb935aed8ca03a5c218ff59e..374af6ad909c3da309dd6d01db9a08129792a914 100644 (file)
@@ -1649,7 +1649,7 @@ struct UserDefined {
   void *out;         /* CURLOPT_WRITEDATA */
   void *in_set;      /* CURLOPT_READDATA */
   void *writeheader; /* write the header to this if non-NULL */
-  long use_port;     /* which port to use (when not using default) */
+  unsigned short use_port; /* which port to use (when not using default) */
   unsigned long httpauth;  /* kind of HTTP authentication to use (bitmask) */
   unsigned long proxyauth; /* kind of proxy authentication to use (bitmask) */
 #ifndef CURL_DISABLE_PROXY