From 44518f8483789103e62f2946949ba8e51d25b6a0 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Sun, 26 Jul 2009 22:26:37 +1200 Subject: [PATCH] Fix FTP EPSV negotiation parser. No longer ignores single-value hints returned ie (1) --- src/ftp.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ftp.cc b/src/ftp.cc index d0e1945f83..b50d299a6e 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -2447,9 +2447,13 @@ ftpReadEPSV(FtpStateData* ftpState) /* server response with list of supported methods */ /* 522 Network protocol not supported, use (1) */ /* 522 Network protocol not supported, use (1,2) */ + /* TODO: handle the (1,2) case. We might get it back after EPSV ALL + * which means close data + control without self-destructing and re-open from scratch. */ debugs(9, 5, HERE << "scanning: " << ftpState->ctrl.last_reply); + buf = ftpState->ctrl.last_reply; + while (buf != NULL && *buf != '\0' && *buf != '\n' && *buf != '(') ++buf; + if (buf != NULL && *buf == '\n') ++buf; - buf = ftpState->ctrl.last_reply + strcspn(ftpState->ctrl.last_reply, "(1,2)"); if (buf == NULL || *buf == '\0') { /* handle broken server (RFC 2428 says MUST specify supported protocols in 522) */ debugs(9, DBG_IMPORTANT, "Broken FTP Server at " << fd_table[ftpState->ctrl.fd].ipaddr << ". 522 error missing protocol negotiation hints"); @@ -2473,6 +2477,11 @@ ftpReadEPSV(FtpStateData* ftpState) ftpSendPassive(ftpState); #endif } + else { + /* handle broken server (RFC 2428 says MUST specify supported protocols in 522) */ + debugs(9, DBG_IMPORTANT, "WARNING: Server at " << fd_table[ftpState->ctrl.fd].ipaddr << " sent unknown protocol negotiation hint: " << buf); + ftpSendPassive(ftpState); + } return; } -- 2.47.3