]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
bindlocal: don't use a random port if port number would wrap
authorHarry Sintonen <sintonen@iki.fi>
Mon, 16 May 2022 19:18:04 +0000 (22:18 +0300)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 17 May 2022 06:53:25 +0000 (08:53 +0200)
Earlier if CURLOPT_LOCALPORT + CURLOPT_LOCALPORTRANGE would go past port
65535 the code would fall back to random port rather than giving up.

Closes #8862

lib/connect.c

index 9bcf525ebb39f8b010d6491e0eb2b6a940be65c3..a50c09a3385bf5f04d191b9312ccb5bc85f54ea0 100644 (file)
@@ -470,8 +470,10 @@ static CURLcode bindlocal(struct Curl_easy *data,
     }
 
     if(--portnum > 0) {
-      infof(data, "Bind to local port %hu failed, trying next", port);
       port++; /* try next port */
+      if(port == 0)
+        break;
+      infof(data, "Bind to local port %hu failed, trying next", port - 1);
       /* We re-use/clobber the port variable here below */
       if(sock->sa_family == AF_INET)
         si4->sin_port = ntohs(port);