浏览代码

Bug 1845: Failure when fallback SSH channel fails to open

https://winscp.net/tracker/1845

Source commit: 1f5324917d99f20b9574d37cb47013d61a7430e4
Martin Prikryl 5 年之前
父节点
当前提交
d8df949fd1
共有 3 个文件被更改,包括 17 次插入2 次删除
  1. 3 2
      source/core/PuttyIntf.cpp
  2. 12 0
      source/core/SecureShell.cpp
  3. 2 0
      source/core/SecureShell.h

+ 3 - 2
source/core/PuttyIntf.cpp

@@ -166,9 +166,10 @@ static size_t output(Seat * seat, bool is_stderr, const void * data, size_t len)
   return 0;
 }
 //---------------------------------------------------------------------------
-static bool eof(Seat *)
+static bool eof(Seat * seat)
 {
-  return false;
+  TSecureShell * SecureShell = static_cast<ScpSeat *>(seat)->SecureShell;
+  return SecureShell->EofReceived();
 }
 //---------------------------------------------------------------------------
 static int get_userpass_input(Seat * seat, prompts_t * p, bufchain * DebugUsedArg(input))

+ 12 - 0
source/core/SecureShell.cpp

@@ -74,6 +74,7 @@ __fastcall TSecureShell::TSecureShell(TSessionUI* UI,
   FSimple = false;
   FCollectPrivateKeyUsage = false;
   FWaitingForData = 0;
+  FSentEof = false;
   FCallbackSet.reset(new callback_set());
   memset(FCallbackSet.get(), 0, sizeof(callback_set));
 }
@@ -101,6 +102,7 @@ void __fastcall TSecureShell::ResetConnection()
   FStoredPasswordTried = false;
   FStoredPasswordTriedForKI = false;
   FStoredPassphraseTried = false;
+  FSentEof = false;
   delete FLogPolicy;
   FLogPolicy = NULL;
   delete FSeat;
@@ -1002,6 +1004,15 @@ void __fastcall TSecureShell::UnregisterReceiveHandler(TNotifyEvent Handler)
   FOnReceive = NULL;
 }
 //---------------------------------------------------------------------------
+bool __fastcall TSecureShell::EofReceived()
+{
+  if (!FSentEof)
+  {
+    FatalError(MainInstructions(LoadStr(NOT_CONNECTED)));
+  }
+  return false;
+}
+//---------------------------------------------------------------------------
 void __fastcall TSecureShell::FromBackend(const unsigned char * Data, size_t Length)
 {
   // Note that we do not apply ConvertFromPutty to Data yet (as opposite to CWrite).
@@ -1691,6 +1702,7 @@ void __fastcall TSecureShell::Close()
   {
     // this is particularly necessary when using local proxy command
     // (e.g. plink), otherwise it hangs in sk_localproxy_close
+    FSentEof = true;
     SendSpecial(SS_EOF);
     // Try waiting for the EOF exchange to complete (among other to avoid packet queue memory leaks)
     int Timeout = 500;

+ 2 - 0
source/core/SecureShell.h

@@ -76,6 +76,7 @@ private:
   ScpLogPolicy * FLogPolicy;
   ScpSeat * FSeat;
   LogContext * FLogCtx;
+  bool FSentEof;
 
   void __fastcall Init();
   void __fastcall SetActive(bool value);
@@ -155,6 +156,7 @@ public:
     UnicodeString AName, bool NameRequired,
     UnicodeString Instructions, bool InstructionsRequired,
     TStrings * Prompts, TStrings * Results);
+  bool __fastcall EofReceived();
   void __fastcall FromBackend(const unsigned char * Data, size_t Length);
   void __fastcall CWrite(const char * Data, size_t Length);
   void __fastcall AddStdError(const char * Data, size_t Length);