Sfoglia il codice sorgente

Invalid FTP response was incorrectly logged when closing transfer connection (caused by cee1be5d)

Source commit: 058b686e4addddc869a112d728f849b9c151fafd
Martin Prikryl 3 anni fa
parent
commit
b62d433c40

+ 25 - 3
source/filezilla/FtpControlSocket.cpp

@@ -1527,12 +1527,16 @@ BOOL CFtpControlSocket::Send(CString str)
   return TRUE;
 }
 
-int CFtpControlSocket::GetReplyCode()
+int CFtpControlSocket::TryGetReplyCode()
 {
   if (m_RecvBuffer.empty())
     return 0;
   CStringA str = m_RecvBuffer.front();
-  if ((str == "") || (str[0] < '1') || (str[0] > '9'))
+  if (str == "")
+  {
+    return -1;
+  }
+  else if ((str[0] < '1') || (str[0] > '9'))
   {
     UnicodeString Error = FMTLOAD(FTP_MALFORMED_RESPONSE, (UnicodeString(str)));
     LogMessageRaw(FZ_LOG_WARNING, Error.c_str());
@@ -1544,6 +1548,18 @@ int CFtpControlSocket::GetReplyCode()
   }
 }
 
+int CFtpControlSocket::GetReplyCode()
+{
+  int Result = TryGetReplyCode();
+  if (Result < 0)
+  {
+    UnicodeString Error = FMTLOAD(FTP_MALFORMED_RESPONSE, (UnicodeString()));
+    LogMessageRaw(FZ_LOG_WARNING, Error.c_str());
+    Result = 0;
+  }
+  return Result;
+}
+
 void CFtpControlSocket::DoClose(int nError /*=0*/)
 {
   LogMessage(FZ_LOG_INFO, L"Connection closed");
@@ -2922,7 +2938,13 @@ void CFtpControlSocket::FileTransfer(t_transferfile *transferfile/*=0*/,BOOL bFi
     ///////////
     //Replies//
     ///////////
-    int code = GetReplyCode();
+    int code = TryGetReplyCode();
+    // We do not always expect a response here, particularly when closing transfer connection (FILETRANSFER_WAITFINISH).
+    // The normalization to 0 is probably not needed.
+    if (code < 0)
+    {
+      code = 0;
+    }
     switch(m_Operation.nOpState)
     {
     case FILETRANSFER_PWD:

+ 1 - 0
source/filezilla/FtpControlSocket.h

@@ -119,6 +119,7 @@ protected:
   void ResetTransferSocket(int Error);
 
   void DoClose(int nError = 0);
+  int TryGetReplyCode();
   int GetReplyCode();
   CString GetReply();
   void LogOnToServer(BOOL bSkipReply = FALSE);