diff options
author | Daniel Stenberg <daniel@haxx.se> | 2016-03-08 00:07:14 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2016-03-08 15:00:53 +0100 |
commit | cb222bcfef3d95e1fb04ca85b2e82e62bb92dfd3 (patch) | |
tree | 1eb4527662e7961d6eadfa19c503429e4d334554 | |
parent | a7ec58a89fe374a3c52ff99d92ba03756dcdadfa (diff) |
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
-rw-r--r-- | lib/ftp.c | 30 |
1 files changed, 15 insertions, 15 deletions
@@ -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; } } |