1
0
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:
Daniel Stenberg 2016-03-08 00:07:14 +01:00
parent a7ec58a89f
commit cb222bcfef

View File

@ -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 * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * 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
#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 * 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); CURLSOCKTYPE_ACCEPT);
if(error) { if(error) {
Curl_closesocket(conn, s); /* close the socket and bail out */ close_secondarysocket(conn);
conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD;
return CURLE_ABORTED_BY_CALLBACK; return CURLE_ABORTED_BY_CALLBACK;
} }
} }
@ -1325,11 +1333,11 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
/* store which command was sent */ /* store which command was sent */
ftpc->count1 = fcmd; ftpc->count1 = fcmd;
close_secondarysocket(conn);
/* we set the secondary socket variable to this for now, it is only so that /* 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 the cleanup function will close it in case we fail before the true
secondary stuff is made */ secondary stuff is made */
if(CURL_SOCKET_BAD != conn->sock[SECONDARYSOCKET])
Curl_closesocket(conn, conn->sock[SECONDARYSOCKET]);
conn->sock[SECONDARYSOCKET] = portsock; conn->sock[SECONDARYSOCKET] = portsock;
/* this tcpconnect assignment below is a hackish work-around to make the /* 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 /* Note that we keep "use" set to TRUE since that (next) connection is
still requested to use SSL */ still requested to use SSL */
} }
if(CURL_SOCKET_BAD != conn->sock[SECONDARYSOCKET]) { close_secondarysocket(conn);
Curl_closesocket(conn, conn->sock[SECONDARYSOCKET]);
conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD;
conn->bits.tcpconnect[SECONDARYSOCKET] = FALSE;
}
} }
if(!result && (ftp->transfer == FTPTRANSFER_BODY) && ftpc->ctl_valid && 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); CURLcode result = ftp_do_more(conn, &completed);
if(result) { if(result) {
if(conn->sock[SECONDARYSOCKET] != CURL_SOCKET_BAD) { close_secondarysocket(conn);
/* close the second socket if it was created already */
Curl_closesocket(conn, conn->sock[SECONDARYSOCKET]);
conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD;
}
return result; return result;
} }
} }