aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Holme <steve_holme@hotmail.com>2013-11-16 22:56:11 +0000
committerSteve Holme <steve_holme@hotmail.com>2013-11-17 00:27:18 +0000
commit2c7a5578e1ad14bbdee77a335595a3c3e96dbbf7 (patch)
tree1288fb4ea8731c3b0673393883e0b498c4a53436
parentb56d7cda741971d5737c326d9452bfe5836bf989 (diff)
connect: Close open but unconnected socket in singleipconnect()
singleipconnect() could return the file descriptor of an open socket even though the function returned a CURLE_COULDNT_CONNECT error code from commit ed1662c374361a and 02fbc26d59c591. This could cause tests 19, 704 and 1233 to fail on FreeBSD, AIX and Solaris.
-rw-r--r--lib/connect.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/connect.c b/lib/connect.c
index e4d4fee4b..3cbca1b50 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -562,6 +562,7 @@ static CURLcode trynextip(struct connectdata *conn,
while(ai && ai->ai_family != family)
ai = ai->ai_next;
+
if(ai) {
rc = singleipconnect(conn, ai, &conn->tempsock[tempindex]);
conn->tempaddr[tempindex] = ai;
@@ -1027,10 +1028,8 @@ singleipconnect(struct connectdata *conn,
conn->bits.ipv6 = (addr.family == AF_INET6)?TRUE:FALSE;
#endif
- *sockp = sockfd;
-
if(-1 == rc) {
- switch (error) {
+ switch(error) {
case EINPROGRESS:
case EWOULDBLOCK:
#if defined(EAGAIN)
@@ -1042,7 +1041,8 @@ singleipconnect(struct connectdata *conn,
case EAGAIN:
#endif
#endif
- return CURLE_OK;
+ res = CURLE_OK;
+ break;
default:
/* unknown error, fallthrough and try another address! */
@@ -1051,11 +1051,15 @@ singleipconnect(struct connectdata *conn,
data->state.os_errno = error;
/* connect failed */
- return CURLE_COULDNT_CONNECT;
+ Curl_closesocket(conn, sockfd);
+ res = CURLE_COULDNT_CONNECT;
}
}
- return CURLE_OK;
+ if(!res)
+ *sockp = sockfd;
+
+ return res;
}
/*