mirror of
https://github.com/moparisthebest/curl
synced 2024-12-23 16:48:49 -05:00
hostip: make Curl_printable_address not return anything
It was not used much anyway and instead we let it store a blank buffer in case of failure. Reported-by: MonocleAI Fixes #5411 Closes #5418
This commit is contained in:
parent
dbc5c17738
commit
67521b5ecf
@ -960,11 +960,12 @@ CURLcode Curl_is_connected(struct connectdata *conn,
|
|||||||
#ifndef CURL_DISABLE_VERBOSE_STRINGS
|
#ifndef CURL_DISABLE_VERBOSE_STRINGS
|
||||||
char ipaddress[MAX_IPADR_LEN];
|
char ipaddress[MAX_IPADR_LEN];
|
||||||
char buffer[STRERROR_LEN];
|
char buffer[STRERROR_LEN];
|
||||||
Curl_printable_address(conn->tempaddr[i], ipaddress, MAX_IPADR_LEN);
|
Curl_printable_address(conn->tempaddr[i], ipaddress,
|
||||||
#endif
|
sizeof(ipaddress));
|
||||||
infof(data, "connect to %s port %ld failed: %s\n",
|
infof(data, "connect to %s port %ld failed: %s\n",
|
||||||
ipaddress, conn->port,
|
ipaddress, conn->port,
|
||||||
Curl_strerror(error, buffer, sizeof(buffer)));
|
Curl_strerror(error, buffer, sizeof(buffer)));
|
||||||
|
#endif
|
||||||
|
|
||||||
conn->timeoutms_per_addr = conn->tempaddr[i]->ai_next == NULL ?
|
conn->timeoutms_per_addr = conn->tempaddr[i]->ai_next == NULL ?
|
||||||
allow : allow / 2;
|
allow : allow / 2;
|
||||||
|
37
lib/hostip.c
37
lib/hostip.c
@ -131,39 +131,36 @@ int Curl_num_addresses(const struct Curl_addrinfo *addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Curl_printable_address() returns a printable version of the 1st address
|
* Curl_printable_address() stores a printable version of the 1st address
|
||||||
* given in the 'ai' argument. The result will be stored in the buf that is
|
* given in the 'ai' argument. The result will be stored in the buf that is
|
||||||
* bufsize bytes big.
|
* bufsize bytes big.
|
||||||
*
|
*
|
||||||
* If the conversion fails, it returns NULL.
|
* If the conversion fails, the target buffer is empty.
|
||||||
*/
|
*/
|
||||||
const char *Curl_printable_address(const struct Curl_addrinfo *ai, char *buf,
|
void Curl_printable_address(const struct Curl_addrinfo *ai, char *buf,
|
||||||
size_t bufsize)
|
size_t bufsize)
|
||||||
{
|
{
|
||||||
const struct sockaddr_in *sa4;
|
DEBUGASSERT(bufsize);
|
||||||
const struct in_addr *ipaddr4;
|
buf[0] = 0;
|
||||||
#ifdef ENABLE_IPV6
|
|
||||||
const struct sockaddr_in6 *sa6;
|
|
||||||
const struct in6_addr *ipaddr6;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch(ai->ai_family) {
|
switch(ai->ai_family) {
|
||||||
case AF_INET:
|
case AF_INET: {
|
||||||
sa4 = (const void *)ai->ai_addr;
|
const struct sockaddr_in *sa4 = (const void *)ai->ai_addr;
|
||||||
ipaddr4 = &sa4->sin_addr;
|
const struct in_addr *ipaddr4 = &sa4->sin_addr;
|
||||||
return Curl_inet_ntop(ai->ai_family, (const void *)ipaddr4, buf,
|
(void)Curl_inet_ntop(ai->ai_family, (const void *)ipaddr4, buf, bufsize);
|
||||||
bufsize);
|
break;
|
||||||
|
}
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
case AF_INET6:
|
case AF_INET6: {
|
||||||
sa6 = (const void *)ai->ai_addr;
|
const struct sockaddr_in6 *sa6 = (const void *)ai->ai_addr;
|
||||||
ipaddr6 = &sa6->sin6_addr;
|
const struct in6_addr *ipaddr6 = &sa6->sin6_addr;
|
||||||
return Curl_inet_ntop(ai->ai_family, (const void *)ipaddr6, buf,
|
(void)Curl_inet_ntop(ai->ai_family, (const void *)ipaddr6, buf, bufsize);
|
||||||
bufsize);
|
break;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -165,7 +165,7 @@ CURLcode Curl_addrinfo_callback(struct connectdata *conn,
|
|||||||
* given in the 'ip' argument. The result will be stored in the buf that is
|
* given in the 'ip' argument. The result will be stored in the buf that is
|
||||||
* bufsize bytes big.
|
* bufsize bytes big.
|
||||||
*/
|
*/
|
||||||
const char *Curl_printable_address(const struct Curl_addrinfo *ip,
|
void Curl_printable_address(const struct Curl_addrinfo *ip,
|
||||||
char *buf, size_t bufsize);
|
char *buf, size_t bufsize);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -111,13 +111,8 @@ static void dump_addrinfo(struct connectdata *conn,
|
|||||||
char buf[INET6_ADDRSTRLEN];
|
char buf[INET6_ADDRSTRLEN];
|
||||||
printf(" fam %2d, CNAME %s, ",
|
printf(" fam %2d, CNAME %s, ",
|
||||||
ai->ai_family, ai->ai_canonname ? ai->ai_canonname : "<none>");
|
ai->ai_family, ai->ai_canonname ? ai->ai_canonname : "<none>");
|
||||||
if(Curl_printable_address(ai, buf, sizeof(buf)))
|
Curl_printable_address(ai, buf, sizeof(buf));
|
||||||
printf("%s\n", buf);
|
printf("%s\n", buf);
|
||||||
else {
|
|
||||||
char buffer[STRERROR_LEN];
|
|
||||||
printf("failed; %s\n",
|
|
||||||
Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -774,6 +774,7 @@ CURLcode Curl_SOCKS5(const char *proxy_user,
|
|||||||
CONNECT_RESOLVED:
|
CONNECT_RESOLVED:
|
||||||
case CONNECT_RESOLVED: {
|
case CONNECT_RESOLVED: {
|
||||||
struct Curl_addrinfo *hp = NULL;
|
struct Curl_addrinfo *hp = NULL;
|
||||||
|
size_t destlen;
|
||||||
if(dns)
|
if(dns)
|
||||||
hp = dns->addr;
|
hp = dns->addr;
|
||||||
if(!hp) {
|
if(!hp) {
|
||||||
@ -782,13 +783,9 @@ CURLcode Curl_SOCKS5(const char *proxy_user,
|
|||||||
return CURLE_COULDNT_RESOLVE_HOST;
|
return CURLE_COULDNT_RESOLVE_HOST;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Curl_printable_address(hp, dest, sizeof(dest))) {
|
Curl_printable_address(hp, dest, sizeof(dest));
|
||||||
size_t destlen = strlen(dest);
|
destlen = strlen(dest);
|
||||||
msnprintf(dest + destlen, sizeof(dest) - destlen, ":%d", remote_port);
|
msnprintf(dest + destlen, sizeof(dest) - destlen, ":%d", remote_port);
|
||||||
}
|
|
||||||
else {
|
|
||||||
strcpy(dest, "unknown");
|
|
||||||
}
|
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
socksreq[len++] = 5; /* version (SOCKS5) */
|
socksreq[len++] = 5; /* version (SOCKS5) */
|
||||||
|
Loading…
Reference in New Issue
Block a user