mirror of
https://github.com/curl/curl.git
synced 2025-09-20 11:02:42 +03:00
Curl_inet_ntop: always check the return code
Reported-by: Siva Sivaraman Fixes #5412 Closes #5597
This commit is contained in:
parent
550bcdd442
commit
d2baa502fc
|
@ -1043,6 +1043,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
|
||||||
} /* data->set.ftpport */
|
} /* data->set.ftpport */
|
||||||
|
|
||||||
if(!host) {
|
if(!host) {
|
||||||
|
const char *r;
|
||||||
/* not an interface and not a host name, get default by extracting
|
/* not an interface and not a host name, get default by extracting
|
||||||
the IP from the control connection */
|
the IP from the control connection */
|
||||||
sslen = sizeof(ss);
|
sslen = sizeof(ss);
|
||||||
|
@ -1055,13 +1056,15 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
|
||||||
switch(sa->sa_family) {
|
switch(sa->sa_family) {
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
Curl_inet_ntop(sa->sa_family, &sa6->sin6_addr, hbuf, sizeof(hbuf));
|
r = Curl_inet_ntop(sa->sa_family, &sa6->sin6_addr, hbuf, sizeof(hbuf));
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
Curl_inet_ntop(sa->sa_family, &sa4->sin_addr, hbuf, sizeof(hbuf));
|
r = Curl_inet_ntop(sa->sa_family, &sa4->sin_addr, hbuf, sizeof(hbuf));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if(!r)
|
||||||
|
return CURLE_FTP_PORT_FAILED;
|
||||||
host = hbuf; /* use this host name */
|
host = hbuf; /* use this host name */
|
||||||
possibly_non_local = FALSE; /* we know it is local now */
|
possibly_non_local = FALSE; /* we know it is local now */
|
||||||
}
|
}
|
||||||
|
|
13
lib/if2ip.c
13
lib/if2ip.c
|
@ -118,7 +118,7 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
|
||||||
if(iface->ifa_addr->sa_family == af) {
|
if(iface->ifa_addr->sa_family == af) {
|
||||||
if(strcasecompare(iface->ifa_name, interf)) {
|
if(strcasecompare(iface->ifa_name, interf)) {
|
||||||
void *addr;
|
void *addr;
|
||||||
char *ip;
|
const char *ip;
|
||||||
char scope[12] = "";
|
char scope[12] = "";
|
||||||
char ipstr[64];
|
char ipstr[64];
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
|
@ -153,15 +153,15 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
|
||||||
}
|
}
|
||||||
|
|
||||||
if(scopeid)
|
if(scopeid)
|
||||||
msnprintf(scope, sizeof(scope), "%%%u", scopeid);
|
msnprintf(scope, sizeof(scope), "%%%u", scopeid);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
addr =
|
addr =
|
||||||
&((struct sockaddr_in *)(void *)iface->ifa_addr)->sin_addr;
|
&((struct sockaddr_in *)(void *)iface->ifa_addr)->sin_addr;
|
||||||
res = IF2IP_FOUND;
|
res = IF2IP_FOUND;
|
||||||
ip = (char *) Curl_inet_ntop(af, addr, ipstr, sizeof(ipstr));
|
ip = Curl_inet_ntop(af, addr, ipstr, sizeof(ipstr));
|
||||||
msnprintf(buf, buf_size, "%s%s", ip, scope);
|
msnprintf(buf, buf_size, "%s%s", ip, scope);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -190,6 +190,7 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
|
||||||
struct sockaddr_in *s;
|
struct sockaddr_in *s;
|
||||||
curl_socket_t dummy;
|
curl_socket_t dummy;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
const char *r;
|
||||||
|
|
||||||
(void)remote_scope;
|
(void)remote_scope;
|
||||||
(void)local_scope_id;
|
(void)local_scope_id;
|
||||||
|
@ -219,9 +220,11 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
|
||||||
|
|
||||||
s = (struct sockaddr_in *)(void *)&req.ifr_addr;
|
s = (struct sockaddr_in *)(void *)&req.ifr_addr;
|
||||||
memcpy(&in, &s->sin_addr, sizeof(in));
|
memcpy(&in, &s->sin_addr, sizeof(in));
|
||||||
Curl_inet_ntop(s->sin_family, &in, buf, buf_size);
|
r = Curl_inet_ntop(s->sin_family, &in, buf, buf_size);
|
||||||
|
|
||||||
sclose(dummy);
|
sclose(dummy);
|
||||||
|
if(!r)
|
||||||
|
return IF2IP_NOT_FOUND;
|
||||||
return IF2IP_FOUND;
|
return IF2IP_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user