summaryrefslogtreecommitdiff
path: root/lib/ftp.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2016-03-08 00:07:14 +0100
committerDaniel Stenberg <daniel@haxx.se>2016-03-08 15:00:53 +0100
commitcb222bcfef3d95e1fb04ca85b2e82e62bb92dfd3 (patch)
tree1eb4527662e7961d6eadfa19c503429e4d334554 /lib/ftp.c
parenta7ec58a89fe374a3c52ff99d92ba03756dcdadfa (diff)
downloadcurl-cb222bcfef3d95e1fb04ca85b2e82e62bb92dfd3.tar.gz
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
Diffstat (limited to 'lib/ftp.c')
-rw-r--r--lib/ftp.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/ftp.c b/lib/ftp.c
index b5a7f55fa..1008c635f 100644
--- a/lib/ftp.c
+++ b/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;
}
}