From: Harry Sintonen Date: Mon, 16 May 2022 19:18:04 +0000 (+0300) Subject: bindlocal: don't use a random port if port number would wrap X-Git-Tag: curl-7_84_0~183 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b3dcaed9fecd614135faaef243151f8085af7e5;p=thirdparty%2Fcurl.git bindlocal: don't use a random port if port number would wrap 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 --- diff --git a/lib/connect.c b/lib/connect.c index 9bcf525ebb..a50c09a338 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -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);