diff options
author | Daniel Stenberg <daniel@haxx.se> | 2024-05-10 10:52:58 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2024-05-10 15:54:50 +0200 |
commit | 4d38cea94ff6d7d5269a19674b876c9f0c83782b (patch) | |
tree | 44cdb672efe9b52ad724c672cdbe438f96dcc000 | |
parent | cabbb9b2a5a5dfec0709ceb19a731af2bf012cf2 (diff) | |
download | curl-4d38cea94ff6d7d5269a19674b876c9f0c83782b.tar.gz |
cf-socket: don't try getting local IP without socket
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
-rw-r--r-- | lib/cf-socket.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/cf-socket.c b/lib/cf-socket.c index eeae5f995..63826fbc1 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -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]; |