mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 08:08:50 -05:00
- Bug #2218480 (http://curl.haxx.se/bug/view.cgi?id=2218480) pointed out a
problem with my CURLINFO_PRIMARY_IP fix from October 7th that caused a NULL pointer read. I also took the opportunity to clean up this logic (storing of the connection's IP address) somewhat as we had it stored in two different places and ways previously and they are now unified.
This commit is contained in:
parent
efe2ce3647
commit
d0b8b5a199
7
CHANGES
7
CHANGES
@ -6,6 +6,13 @@
|
|||||||
|
|
||||||
Changelog
|
Changelog
|
||||||
|
|
||||||
|
Daniel Stenberg (3 Nov 2008)
|
||||||
|
- Bug #2218480 (http://curl.haxx.se/bug/view.cgi?id=2218480) pointed out a
|
||||||
|
problem with my CURLINFO_PRIMARY_IP fix from October 7th that caused a NULL
|
||||||
|
pointer read. I also took the opportunity to clean up this logic (storing of
|
||||||
|
the connection's IP address) somewhat as we had it stored in two different
|
||||||
|
places and ways previously and they are now unified.
|
||||||
|
|
||||||
Daniel Stenberg (2 Nov 2008)
|
Daniel Stenberg (2 Nov 2008)
|
||||||
- Daniel Johnson reported and fixed:
|
- Daniel Johnson reported and fixed:
|
||||||
|
|
||||||
|
@ -555,25 +555,6 @@ static bool verifyconnect(curl_socket_t sockfd, int *error)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
CURLcode Curl_store_ip_addr(struct connectdata *conn)
|
|
||||||
{
|
|
||||||
char addrbuf[256];
|
|
||||||
Curl_printable_address(conn->ip_addr, addrbuf, sizeof(addrbuf));
|
|
||||||
|
|
||||||
/* save the string */
|
|
||||||
Curl_safefree(conn->ip_addr_str);
|
|
||||||
conn->ip_addr_str = strdup(addrbuf);
|
|
||||||
if(!conn->ip_addr_str)
|
|
||||||
return CURLE_OUT_OF_MEMORY; /* FAIL */
|
|
||||||
|
|
||||||
#ifdef PF_INET6
|
|
||||||
if(conn->ip_addr->ai_family == PF_INET6)
|
|
||||||
conn->bits.ipv6 = TRUE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return CURLE_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Used within the multi interface. Try next IP address, return TRUE if no
|
/* Used within the multi interface. Try next IP address, return TRUE if no
|
||||||
more address exists or error */
|
more address exists or error */
|
||||||
static bool trynextip(struct connectdata *conn,
|
static bool trynextip(struct connectdata *conn,
|
||||||
@ -600,8 +581,7 @@ static bool trynextip(struct connectdata *conn,
|
|||||||
/* store the new socket descriptor */
|
/* store the new socket descriptor */
|
||||||
conn->sock[sockindex] = sockfd;
|
conn->sock[sockindex] = sockfd;
|
||||||
conn->ip_addr = ai;
|
conn->ip_addr = ai;
|
||||||
|
break;
|
||||||
return (bool)(Curl_store_ip_addr(conn) != CURLE_OK);
|
|
||||||
}
|
}
|
||||||
ai = ai->ai_next;
|
ai = ai->ai_next;
|
||||||
}
|
}
|
||||||
@ -824,21 +804,27 @@ singleipconnect(struct connectdata *conn,
|
|||||||
((const struct sockaddr_un*)(&addr.sa_addr))->sun_path);
|
((const struct sockaddr_un*)(&addr.sa_addr))->sun_path);
|
||||||
snprintf(data->info.ip, MAX_IPADR_LEN, "%s",
|
snprintf(data->info.ip, MAX_IPADR_LEN, "%s",
|
||||||
((const struct sockaddr_un*)(&addr.sa_addr))->sun_path);
|
((const struct sockaddr_un*)(&addr.sa_addr))->sun_path);
|
||||||
|
strcpy(conn->ip_addr_str, data->info.ip);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
if(addr.family == AF_INET6)
|
if(addr.family == AF_INET6) {
|
||||||
iptoprint = &sa6->sin6_addr;
|
iptoprint = &sa6->sin6_addr;
|
||||||
|
conn->bits.ipv6 = TRUE;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
iptoprint = &sa4->sin_addr;
|
iptoprint = &sa4->sin_addr;
|
||||||
|
}
|
||||||
|
|
||||||
if(Curl_inet_ntop(addr.family, iptoprint, addr_buf,
|
if(Curl_inet_ntop(addr.family, iptoprint, addr_buf,
|
||||||
sizeof(addr_buf)) != NULL) {
|
sizeof(addr_buf)) != NULL) {
|
||||||
infof(data, " Trying %s... ", addr_buf);
|
infof(data, " Trying %s... ", addr_buf);
|
||||||
snprintf(data->info.ip, MAX_IPADR_LEN, "%s", addr_buf);
|
snprintf(data->info.ip, MAX_IPADR_LEN, "%s", addr_buf);
|
||||||
|
strcpy(conn->ip_addr_str, data->info.ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,8 +37,6 @@ CURLcode Curl_connecthost(struct connectdata *conn,
|
|||||||
Curl_addrinfo **addr, /* the one we used */
|
Curl_addrinfo **addr, /* the one we used */
|
||||||
bool *connected); /* truly connected? */
|
bool *connected); /* truly connected? */
|
||||||
|
|
||||||
CURLcode Curl_store_ip_addr(struct connectdata *conn);
|
|
||||||
|
|
||||||
/* generic function that returns how much time there's left to run, according
|
/* generic function that returns how much time there's left to run, according
|
||||||
to the timeouts set */
|
to the timeouts set */
|
||||||
long Curl_timeleft(struct connectdata *conn,
|
long Curl_timeleft(struct connectdata *conn,
|
||||||
|
16
lib/url.c
16
lib/url.c
@ -2174,7 +2174,6 @@ static void conn_free(struct connectdata *conn)
|
|||||||
Curl_safefree(conn->allocptr.ref);
|
Curl_safefree(conn->allocptr.ref);
|
||||||
Curl_safefree(conn->allocptr.host);
|
Curl_safefree(conn->allocptr.host);
|
||||||
Curl_safefree(conn->allocptr.cookiehost);
|
Curl_safefree(conn->allocptr.cookiehost);
|
||||||
Curl_safefree(conn->ip_addr_str);
|
|
||||||
Curl_safefree(conn->trailer);
|
Curl_safefree(conn->trailer);
|
||||||
Curl_safefree(conn->host.rawalloc); /* host name buffer */
|
Curl_safefree(conn->host.rawalloc); /* host name buffer */
|
||||||
Curl_safefree(conn->proxy.rawalloc); /* proxy name buffer */
|
Curl_safefree(conn->proxy.rawalloc); /* proxy name buffer */
|
||||||
@ -2479,9 +2478,9 @@ ConnectionExists(struct SessionHandle *data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CURLRES_ASYNCH
|
#ifdef CURLRES_ASYNCH
|
||||||
/* ip_addr_str is NULL only if the resolving of the name hasn't completed
|
/* ip_addr_str[0] is NUL only if the resolving of the name hasn't
|
||||||
yet and until then we don't re-use this connection */
|
completed yet and until then we don't re-use this connection */
|
||||||
if(!check->ip_addr_str) {
|
if(!check->ip_addr_str[0]) {
|
||||||
infof(data,
|
infof(data,
|
||||||
"Connection #%ld hasn't finished name resolve, can't reuse\n",
|
"Connection #%ld hasn't finished name resolve, can't reuse\n",
|
||||||
check->connectindex);
|
check->connectindex);
|
||||||
@ -2727,9 +2726,6 @@ static CURLcode ConnectPlease(struct SessionHandle *data,
|
|||||||
conn->dns_entry = hostaddr;
|
conn->dns_entry = hostaddr;
|
||||||
conn->ip_addr = addr;
|
conn->ip_addr = addr;
|
||||||
|
|
||||||
result = Curl_store_ip_addr(conn);
|
|
||||||
|
|
||||||
if(CURLE_OK == result) {
|
|
||||||
switch(data->set.proxytype) {
|
switch(data->set.proxytype) {
|
||||||
#ifndef CURL_DISABLE_PROXY
|
#ifndef CURL_DISABLE_PROXY
|
||||||
case CURLPROXY_SOCKS5:
|
case CURLPROXY_SOCKS5:
|
||||||
@ -2754,9 +2750,9 @@ static CURLcode ConnectPlease(struct SessionHandle *data,
|
|||||||
failf(data, "unknown proxytype option given");
|
failf(data, "unknown proxytype option given");
|
||||||
result = CURLE_COULDNT_CONNECT;
|
result = CURLE_COULDNT_CONNECT;
|
||||||
break;
|
break;
|
||||||
}
|
} /* switch proxytype */
|
||||||
}
|
} /* if result is ok */
|
||||||
}
|
|
||||||
if(result)
|
if(result)
|
||||||
*connected = FALSE; /* mark it as not connected */
|
*connected = FALSE; /* mark it as not connected */
|
||||||
|
|
||||||
|
@ -908,11 +908,10 @@ struct connectdata {
|
|||||||
cache entry remains locked. It gets unlocked in Curl_done() */
|
cache entry remains locked. It gets unlocked in Curl_done() */
|
||||||
Curl_addrinfo *ip_addr;
|
Curl_addrinfo *ip_addr;
|
||||||
|
|
||||||
/* 'ip_addr_str' is the ip_addr data as a human readable malloc()ed string.
|
/* 'ip_addr_str' is the ip_addr data as a human readable string.
|
||||||
It remains available as long as the connection does, which is longer than
|
It remains available as long as the connection does, which is longer than
|
||||||
the ip_addr itself. Set with Curl_store_ip_addr() when ip_addr has been
|
the ip_addr itself. */
|
||||||
set. */
|
char ip_addr_str[MAX_IPADR_LEN];
|
||||||
char *ip_addr_str;
|
|
||||||
|
|
||||||
unsigned int scope; /* address scope for IPv6 */
|
unsigned int scope; /* address scope for IPv6 */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user