mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 08:08:50 -05:00
ftp PORT: don't hang if bind() fails
When the user requests PORT with a specific port or port range, the code could lock up in an endless loop. There's now an extra conditional that makes sure to special treat the error and try the local address only once so a second failure will abort the loop correctly. Bug: http://curl.haxx.se/bug/view.cgi?id=3433968 Reported by: Gokhan Sengun
This commit is contained in:
parent
06a83e8050
commit
e3166df1bb
@ -753,6 +753,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
|
|||||||
unsigned short port_min = 0;
|
unsigned short port_min = 0;
|
||||||
unsigned short port_max = 0;
|
unsigned short port_max = 0;
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
|
bool possibly_non_local = TRUE;
|
||||||
|
|
||||||
char *addr = NULL;
|
char *addr = NULL;
|
||||||
|
|
||||||
@ -869,6 +870,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
host = hbuf; /* use this host name */
|
host = hbuf; /* use this host name */
|
||||||
|
possibly_non_local = FALSE; /* we know it is local now */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* resolv ip/host to ip */
|
/* resolv ip/host to ip */
|
||||||
@ -932,12 +934,12 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
|
|||||||
if(bind(portsock, sa, sslen) ) {
|
if(bind(portsock, sa, sslen) ) {
|
||||||
/* It failed. */
|
/* It failed. */
|
||||||
error = SOCKERRNO;
|
error = SOCKERRNO;
|
||||||
if(error == EADDRNOTAVAIL) {
|
if(possibly_non_local && (error == EADDRNOTAVAIL)) {
|
||||||
|
|
||||||
/* The requested bind address is not local. Use the address used for
|
/* The requested bind address is not local. Use the address used for
|
||||||
* the control connection instead and restart the port loop
|
* the control connection instead and restart the port loop
|
||||||
*/
|
*/
|
||||||
failf(data, "bind(port=%hu) failed: %s", port,
|
|
||||||
|
infof(data, "bind(port=%hu) on non-local address failed: %s", port,
|
||||||
Curl_strerror(conn, error) );
|
Curl_strerror(conn, error) );
|
||||||
|
|
||||||
sslen = sizeof(ss);
|
sslen = sizeof(ss);
|
||||||
@ -948,6 +950,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
|
|||||||
return CURLE_FTP_PORT_FAILED;
|
return CURLE_FTP_PORT_FAILED;
|
||||||
}
|
}
|
||||||
port = port_min;
|
port = port_min;
|
||||||
|
possibly_non_local = FALSE; /* don't try this again */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if(error != EADDRINUSE && error != EACCES) {
|
else if(error != EADDRINUSE && error != EACCES) {
|
||||||
|
Loading…
Reference in New Issue
Block a user