mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
ftp_done: clear tunnel_state when secondary socket closes
Introducing a function for closing the secondary connection to make this bug less likely to happen again. Reported-by: daboul Closes #701
This commit is contained in:
parent
a7ec58a89f
commit
cb222bcfef
30
lib/ftp.c
30
lib/ftp.c
@ -5,7 +5,7 @@
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
@ -265,6 +265,15 @@ static const struct Curl_handler Curl_handler_ftps_proxy = {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static void close_secondarysocket(struct connectdata *conn)
|
||||
{
|
||||
if(CURL_SOCKET_BAD != conn->sock[SECONDARYSOCKET]) {
|
||||
Curl_closesocket(conn, conn->sock[SECONDARYSOCKET]);
|
||||
conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD;
|
||||
}
|
||||
conn->bits.tcpconnect[SECONDARYSOCKET] = FALSE;
|
||||
conn->tunnel_state[SECONDARYSOCKET] = TUNNEL_INIT;
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE: back in the old days, we added code in the FTP code that made NOBODY
|
||||
@ -357,8 +366,7 @@ static CURLcode AcceptServerConnect(struct connectdata *conn)
|
||||
CURLSOCKTYPE_ACCEPT);
|
||||
|
||||
if(error) {
|
||||
Curl_closesocket(conn, s); /* close the socket and bail out */
|
||||
conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD;
|
||||
close_secondarysocket(conn);
|
||||
return CURLE_ABORTED_BY_CALLBACK;
|
||||
}
|
||||
}
|
||||
@ -1325,11 +1333,11 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
|
||||
/* store which command was sent */
|
||||
ftpc->count1 = fcmd;
|
||||
|
||||
close_secondarysocket(conn);
|
||||
|
||||
/* we set the secondary socket variable to this for now, it is only so that
|
||||
the cleanup function will close it in case we fail before the true
|
||||
secondary stuff is made */
|
||||
if(CURL_SOCKET_BAD != conn->sock[SECONDARYSOCKET])
|
||||
Curl_closesocket(conn, conn->sock[SECONDARYSOCKET]);
|
||||
conn->sock[SECONDARYSOCKET] = portsock;
|
||||
|
||||
/* this tcpconnect assignment below is a hackish work-around to make the
|
||||
@ -3360,11 +3368,7 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status,
|
||||
/* Note that we keep "use" set to TRUE since that (next) connection is
|
||||
still requested to use SSL */
|
||||
}
|
||||
if(CURL_SOCKET_BAD != conn->sock[SECONDARYSOCKET]) {
|
||||
Curl_closesocket(conn, conn->sock[SECONDARYSOCKET]);
|
||||
conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD;
|
||||
conn->bits.tcpconnect[SECONDARYSOCKET] = FALSE;
|
||||
}
|
||||
close_secondarysocket(conn);
|
||||
}
|
||||
|
||||
if(!result && (ftp->transfer == FTPTRANSFER_BODY) && ftpc->ctl_valid &&
|
||||
@ -4443,11 +4447,7 @@ static CURLcode ftp_dophase_done(struct connectdata *conn,
|
||||
CURLcode result = ftp_do_more(conn, &completed);
|
||||
|
||||
if(result) {
|
||||
if(conn->sock[SECONDARYSOCKET] != CURL_SOCKET_BAD) {
|
||||
/* close the second socket if it was created already */
|
||||
Curl_closesocket(conn, conn->sock[SECONDARYSOCKET]);
|
||||
conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD;
|
||||
}
|
||||
close_secondarysocket(conn);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user