Browse Source

Connection information is not displayed + It's logged with BOM

Source commit: 7c416bbf1e42b26db5b7fe7d2d1c7778dcc6f57d
Martin Prikryl 6 years ago
parent
commit
949fb00d5e

+ 7 - 5
source/core/PuttyIntf.cpp

@@ -132,15 +132,17 @@ extern "C" char * do_select(Plug * plug, SOCKET skt, bool startup)
 static int output(Seat * seat, bool is_stderr, const void * data, int len)
 {
   TSecureShell * SecureShell = static_cast<ScpSeat *>(seat)->SecureShell;
-  if (is_stderr >= 0)
+  if (static_cast<int>(static_cast<char>(is_stderr)) == -1)
   {
-    DebugAssert((is_stderr == 0) || (is_stderr == 1));
-    SecureShell->FromBackend((is_stderr == 1), reinterpret_cast<const unsigned char *>(data), len);
+    SecureShell->CWrite(reinterpret_cast<const char *>(data), len);
+  }
+  else if (!is_stderr)
+  {
+    SecureShell->FromBackend(reinterpret_cast<const unsigned char *>(data), len);
   }
   else
   {
-    DebugAssert(is_stderr == -1);
-    SecureShell->CWrite(reinterpret_cast<const char *>(data), len);
+    SecureShell->AddStdError(reinterpret_cast<const char *>(data), len);
   }
   return 0;
 }

+ 41 - 47
source/core/SecureShell.cpp

@@ -1025,7 +1025,7 @@ void __fastcall TSecureShell::UnregisterReceiveHandler(TNotifyEvent Handler)
   FOnReceive = NULL;
 }
 //---------------------------------------------------------------------------
-void __fastcall TSecureShell::FromBackend(bool IsStdErr, const unsigned char * Data, int Length)
+void __fastcall TSecureShell::FromBackend(const unsigned char * Data, int Length)
 {
   // Note that we do not apply ConvertFromPutty to Data yet (as opposite to CWrite).
   // as there's no use for this atm.
@@ -1033,69 +1033,62 @@ void __fastcall TSecureShell::FromBackend(bool IsStdErr, const unsigned char * D
 
   if (Configuration->ActualLogProtocol >= 1)
   {
-    LogEvent(FORMAT(L"Received %u bytes (%d)", (Length, int(IsStdErr))));
+    LogEvent(FORMAT(L"Received %u bytes", (Length)));
   }
 
   // Following is taken from scp.c from_backend() and modified
 
-  if (IsStdErr)
-  {
-    AddStdError(ConvertInput(RawByteString(reinterpret_cast<const char *>(Data), Length)));
-  }
-  else
-  {
-    const unsigned char *p = Data;
-    unsigned Len = (unsigned)Length;
+  const unsigned char *p = Data;
+  unsigned Len = (unsigned)Length;
 
-    // with event-select mechanism we can now receive data even before we
-    // actually expect them (OutPtr can be NULL)
+  // with event-select mechanism we can now receive data even before we
+  // actually expect them (OutPtr can be NULL)
 
-    if ((OutPtr != NULL) && (OutLen > 0) && (Len > 0))
-    {
-      unsigned Used = OutLen;
-      if (Used > Len) Used = Len;
-      memmove(OutPtr, p, Used);
-      OutPtr += Used; OutLen -= Used;
-      p += Used; Len -= Used;
-    }
+  if ((OutPtr != NULL) && (OutLen > 0) && (Len > 0))
+  {
+    unsigned Used = OutLen;
+    if (Used > Len) Used = Len;
+    memmove(OutPtr, p, Used);
+    OutPtr += Used; OutLen -= Used;
+    p += Used; Len -= Used;
+  }
 
-    if (Len > 0)
+  if (Len > 0)
+  {
+    if (PendSize < PendLen + Len)
     {
-      if (PendSize < PendLen + Len)
-      {
-        PendSize = PendLen + Len + 4096;
-        Pending = (unsigned char *)
-          (Pending ? srealloc(Pending, PendSize) : smalloc(PendSize));
-        if (!Pending) FatalError(L"Out of memory");
-      }
-      memmove(Pending + PendLen, p, Len);
-      PendLen += Len;
+      PendSize = PendLen + Len + 4096;
+      Pending = (unsigned char *)
+        (Pending ? srealloc(Pending, PendSize) : smalloc(PendSize));
+      if (!Pending) FatalError(L"Out of memory");
     }
+    memmove(Pending + PendLen, p, Len);
+    PendLen += Len;
+  }
 
-    if (FOnReceive != NULL)
+  if (FOnReceive != NULL)
+  {
+    if (!FFrozen)
     {
-      if (!FFrozen)
+      FFrozen = true;
+      try
       {
-        FFrozen = true;
-        try
-        {
-          do
-          {
-            FDataWhileFrozen = false;
-            FOnReceive(NULL);
-          }
-          while (FDataWhileFrozen);
-        }
-        __finally
+        do
         {
-          FFrozen = false;
+          FDataWhileFrozen = false;
+          FOnReceive(NULL);
         }
+        while (FDataWhileFrozen);
       }
-      else
+      __finally
       {
-        FDataWhileFrozen = true;
+        FFrozen = false;
       }
     }
+    else
+    {
+      FDataWhileFrozen = true;
+    }
   }
 }
 //---------------------------------------------------------------------------
@@ -1461,8 +1454,9 @@ int __fastcall TSecureShell::TranslateAuthenticationMessage(
   return Result;
 }
 //---------------------------------------------------------------------------
-void __fastcall TSecureShell::AddStdError(UnicodeString Str)
+void __fastcall TSecureShell::AddStdError(const char * Data, int Length)
 {
+  UnicodeString Str = ConvertInput(RawByteString(Data, Length));
   FStdError += Str;
 
   Integer P;

+ 2 - 2
source/core/SecureShell.h

@@ -112,7 +112,6 @@ protected:
     size_t Count, UnicodeString & Message, UnicodeString * HelpKeyword = NULL);
   int __fastcall TranslateAuthenticationMessage(UnicodeString & Message, UnicodeString * HelpKeyword = NULL);
   int __fastcall TranslateErrorMessage(UnicodeString & Message, UnicodeString * HelpKeyword = NULL);
-  void __fastcall AddStdError(UnicodeString Str);
   void __fastcall AddStdErrorLine(const UnicodeString & Str);
   void __fastcall inline LogEvent(const UnicodeString & Str);
   void __fastcall FatalError(UnicodeString Error, UnicodeString HelpKeyword = L"");
@@ -157,8 +156,9 @@ public:
     UnicodeString AName, bool NameRequired,
     UnicodeString Instructions, bool InstructionsRequired,
     TStrings * Prompts, TStrings * Results);
-  void __fastcall FromBackend(bool IsStdErr, const unsigned char * Data, int Length);
+  void __fastcall FromBackend(const unsigned char * Data, int Length);
   void __fastcall CWrite(const char * Data, int Length);
+  void __fastcall AddStdError(const char * Data, int Length);
   const UnicodeString & __fastcall GetStdError();
   void __fastcall VerifyHostKey(
     const UnicodeString & Host, int Port, const UnicodeString & KeyType, const UnicodeString & KeyStr,

+ 0 - 1
source/putty/ssh2userauth.c

@@ -475,7 +475,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                         int len;
                         bufchain_prefix(&s->banner, &data, &len);
                         display_banner(s->ppl.seat, &s->banner, len); // WINSCP
-                        seat_stderr(s->ppl.seat, data, len);
                         bufchain_consume(&s->banner, len);
                     }
                 }

+ 2 - 1
source/putty/sshcommon.c

@@ -837,7 +837,8 @@ void ssh_ppl_user_output_string_and_free(PacketProtocolLayer *ppl, char *text)
     /* Messages sent via this function are from the SSH layer, not
      * from the server-side process, so they always have the stderr
      * flag set. */
-    seat_stderr(ppl->seat, text, strlen(text));
+    int stderrflag = -1; // WINSCP
+    seat_output(ppl->seat, *((bool*)&stderrflag), text, strlen(text)); // WINSCP
     sfree(text);
 }