1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-23 08:38: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:
Daniel Stenberg 2020-05-18 18:41:20 +02:00
parent dbc5c17738
commit 67521b5ecf
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
5 changed files with 33 additions and 43 deletions

View File

@ -960,11 +960,12 @@ CURLcode Curl_is_connected(struct connectdata *conn,
#ifndef CURL_DISABLE_VERBOSE_STRINGS
char ipaddress[MAX_IPADR_LEN];
char buffer[STRERROR_LEN];
Curl_printable_address(conn->tempaddr[i], ipaddress, MAX_IPADR_LEN);
#endif
Curl_printable_address(conn->tempaddr[i], ipaddress,
sizeof(ipaddress));
infof(data, "connect to %s port %ld failed: %s\n",
ipaddress, conn->port,
Curl_strerror(error, buffer, sizeof(buffer)));
#endif
conn->timeoutms_per_addr = conn->tempaddr[i]->ai_next == NULL ?
allow : allow / 2;

View File

@ -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
* 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,
size_t bufsize)
void Curl_printable_address(const struct Curl_addrinfo *ai, char *buf,
size_t bufsize)
{
const struct sockaddr_in *sa4;
const struct in_addr *ipaddr4;
#ifdef ENABLE_IPV6
const struct sockaddr_in6 *sa6;
const struct in6_addr *ipaddr6;
#endif
DEBUGASSERT(bufsize);
buf[0] = 0;
switch(ai->ai_family) {
case AF_INET:
sa4 = (const void *)ai->ai_addr;
ipaddr4 = &sa4->sin_addr;
return Curl_inet_ntop(ai->ai_family, (const void *)ipaddr4, buf,
bufsize);
#ifdef ENABLE_IPV6
case AF_INET6:
sa6 = (const void *)ai->ai_addr;
ipaddr6 = &sa6->sin6_addr;
return Curl_inet_ntop(ai->ai_family, (const void *)ipaddr6, buf,
bufsize);
#endif
default:
break;
case AF_INET: {
const struct sockaddr_in *sa4 = (const void *)ai->ai_addr;
const struct in_addr *ipaddr4 = &sa4->sin_addr;
(void)Curl_inet_ntop(ai->ai_family, (const void *)ipaddr4, buf, bufsize);
break;
}
#ifdef ENABLE_IPV6
case AF_INET6: {
const struct sockaddr_in6 *sa6 = (const void *)ai->ai_addr;
const struct in6_addr *ipaddr6 = &sa6->sin6_addr;
(void)Curl_inet_ntop(ai->ai_family, (const void *)ipaddr6, buf, bufsize);
break;
}
#endif
default:
break;
}
return NULL;
}
/*

View File

@ -165,8 +165,8 @@ CURLcode Curl_addrinfo_callback(struct connectdata *conn,
* given in the 'ip' argument. The result will be stored in the buf that is
* bufsize bytes big.
*/
const char *Curl_printable_address(const struct Curl_addrinfo *ip,
char *buf, size_t bufsize);
void Curl_printable_address(const struct Curl_addrinfo *ip,
char *buf, size_t bufsize);
/*
* Curl_fetch_addr() fetches a 'Curl_dns_entry' already in the DNS cache.

View File

@ -111,13 +111,8 @@ static void dump_addrinfo(struct connectdata *conn,
char buf[INET6_ADDRSTRLEN];
printf(" fam %2d, CNAME %s, ",
ai->ai_family, ai->ai_canonname ? ai->ai_canonname : "<none>");
if(Curl_printable_address(ai, buf, sizeof(buf)))
printf("%s\n", buf);
else {
char buffer[STRERROR_LEN];
printf("failed; %s\n",
Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
}
Curl_printable_address(ai, buf, sizeof(buf));
printf("%s\n", buf);
}
}
#else

View File

@ -774,6 +774,7 @@ CURLcode Curl_SOCKS5(const char *proxy_user,
CONNECT_RESOLVED:
case CONNECT_RESOLVED: {
struct Curl_addrinfo *hp = NULL;
size_t destlen;
if(dns)
hp = dns->addr;
if(!hp) {
@ -782,13 +783,9 @@ CURLcode Curl_SOCKS5(const char *proxy_user,
return CURLE_COULDNT_RESOLVE_HOST;
}
if(Curl_printable_address(hp, dest, sizeof(dest))) {
size_t destlen = strlen(dest);
msnprintf(dest + destlen, sizeof(dest) - destlen, ":%d", remote_port);
}
else {
strcpy(dest, "unknown");
}
Curl_printable_address(hp, dest, sizeof(dest));
destlen = strlen(dest);
msnprintf(dest + destlen, sizeof(dest) - destlen, ":%d", remote_port);
len = 0;
socksreq[len++] = 5; /* version (SOCKS5) */