Explorar o código

Bug 2077: Improve error message when FTP server returns malformed response

https://winscp.net/tracker/2077
(cherry picked from commit cee1be5d6226da526fbd6956839b9a341d9c5433)

Source commit: c7529cb8a5b24f1df11cc12ef56b1b2e047e80d0
Martin Prikryl %!s(int64=3) %!d(string=hai) anos
pai
achega
854617ec2f

+ 7 - 1
source/filezilla/FtpControlSocket.cpp

@@ -1534,10 +1534,16 @@ int CFtpControlSocket::GetReplyCode()
   if (m_RecvBuffer.empty())
     return 0;
   CStringA str = m_RecvBuffer.front();
-  if (str == "")
+  if ((str == "") || (str[0] < '1') || (str[0] > '9'))
+  {
+    UnicodeString Error = FMTLOAD(FTP_MALFORMED_RESPONSE, (UnicodeString(str)));
+    LogMessageRaw(FZ_LOG_WARNING, Error.c_str());
     return 0;
+  }
   else
+  {
     return str[0]-'0';
+  }
 }
 
 void CFtpControlSocket::DoClose(int nError /*=0*/)

+ 1 - 0
source/resource/TextsCore.h

@@ -278,6 +278,7 @@
 #define CREATE_TEMP_DIR_ERROR   754
 #define OPENSSH_CONFIG_NOT_FOUND 755
 #define OPENSSH_CONFIG_NO_SITES 756
+#define FTP_MALFORMED_RESPONSE  757
 
 #define CORE_CONFIRMATION_STRINGS 300
 #define CONFIRM_PROLONG_TIMEOUT3 301

+ 1 - 0
source/resource/TextsCore1.rc

@@ -250,6 +250,7 @@ BEGIN
   CREATE_TEMP_DIR_ERROR, "Cannot create temporary directory '%s'. You may change root directory to store temporary files in Preferences."
   OPENSSH_CONFIG_NOT_FOUND, "OpenSSH config file not found."
   OPENSSH_CONFIG_NO_SITES, "No Host directives for specific hosts found in OpenSSH config file."
+  FTP_MALFORMED_RESPONSE, "FTP server returned invalid response '%s'."
 
   CORE_CONFIRMATION_STRINGS, "CORE_CONFIRMATION"
   CONFIRM_PROLONG_TIMEOUT3, "Host is not communicating for %d seconds.\n\nWait for another %0:d seconds?"