]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cf-socket: don't try getting local IP without socket
authorDaniel Stenberg <daniel@haxx.se>
Fri, 10 May 2024 08:52:58 +0000 (10:52 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 10 May 2024 13:54:50 +0000 (15:54 +0200)
In cf_tcp_connect(), it might fail and not get a socket assigned to
ctx->sock but set_local_ip() is still called which would make
getsockname() get invoked with a negative file desriptor and fail.

By adding this check, set_local_ip() will now instead blank out the
fields correctly.

Spotted by CodeSonar

Closes #13577

lib/cf-socket.c

index eeae5f9950c542335f62e2c59fc17fd6b278e4eb..63826fbc1d4e481c7e0ed8a4bee9ab7bb67ca334 100644 (file)
@@ -923,7 +923,8 @@ static CURLcode set_local_ip(struct Curl_cfilter *cf,
   struct cf_socket_ctx *ctx = cf->ctx;
 
 #ifdef HAVE_GETSOCKNAME
-  if(!(data->conn->handler->protocol & CURLPROTO_TFTP)) {
+  if((ctx->sock != CURL_SOCKET_BAD) &&
+     !(data->conn->handler->protocol & CURLPROTO_TFTP)) {
     /* TFTP does not connect, so it cannot get the IP like this */
 
     char buffer[STRERROR_LEN];