فهرست منبع

Updating code to PuTTY 85550641

Source commit: a832bf8e6cf3697a073014ec6cf406224103eb04
Martin Prikryl 6 سال پیش
والد
کامیت
919cf6a535

+ 1 - 1
source/core/PuttyIntf.cpp

@@ -129,7 +129,7 @@ extern "C" char * do_select(Plug * plug, SOCKET skt, bool startup)
   return NULL;
 }
 //---------------------------------------------------------------------------
-static int output(Seat * seat, bool is_stderr, const void * data, int len)
+static size_t output(Seat * seat, bool is_stderr, const void * data, size_t len)
 {
   TSecureShell * SecureShell = static_cast<ScpSeat *>(seat)->SecureShell;
   if (static_cast<int>(static_cast<char>(is_stderr)) == -1)

+ 5 - 5
source/core/SecureShell.cpp

@@ -985,7 +985,7 @@ void __fastcall TSecureShell::GotHostKey()
   }
 }
 //---------------------------------------------------------------------------
-void __fastcall TSecureShell::CWrite(const char * Data, int Length)
+void __fastcall TSecureShell::CWrite(const char * Data, size_t Length)
 {
   // some messages to stderr may indicate that something has changed with the
   // session, so reset the session info
@@ -1025,7 +1025,7 @@ void __fastcall TSecureShell::UnregisterReceiveHandler(TNotifyEvent Handler)
   FOnReceive = NULL;
 }
 //---------------------------------------------------------------------------
-void __fastcall TSecureShell::FromBackend(const unsigned char * Data, int Length)
+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).
   // as there's no use for this atm.
@@ -1033,13 +1033,13 @@ void __fastcall TSecureShell::FromBackend(const unsigned char * Data, int Length
 
   if (Configuration->ActualLogProtocol >= 1)
   {
-    LogEvent(FORMAT(L"Received %u bytes", (Length)));
+    LogEvent(FORMAT(L"Received %u bytes", (static_cast<int>(Length))));
   }
 
   // Following is taken from scp.c from_backend() and modified
 
   const unsigned char *p = Data;
-  unsigned Len = (unsigned)Length;
+  unsigned Len = Length;
 
   // with event-select mechanism we can now receive data even before we
   // actually expect them (OutPtr can be NULL)
@@ -1454,7 +1454,7 @@ int __fastcall TSecureShell::TranslateAuthenticationMessage(
   return Result;
 }
 //---------------------------------------------------------------------------
-void __fastcall TSecureShell::AddStdError(const char * Data, int Length)
+void __fastcall TSecureShell::AddStdError(const char * Data, size_t Length)
 {
   UnicodeString Str = ConvertInput(RawByteString(Data, Length));
   FStdError += Str;

+ 3 - 3
source/core/SecureShell.h

@@ -156,9 +156,9 @@ public:
     UnicodeString AName, bool NameRequired,
     UnicodeString Instructions, bool InstructionsRequired,
     TStrings * Prompts, TStrings * Results);
-  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);
+  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);
   const UnicodeString & __fastcall GetStdError();
   void __fastcall VerifyHostKey(
     const UnicodeString & Host, int Port, const UnicodeString & KeyType, const UnicodeString & KeyStr,

+ 2 - 0
source/putty/be_misc.c

@@ -87,6 +87,7 @@ void log_proxy_stderr(Plug *plug, bufchain *buf, const void *vdata, size_t len)
         /*
          * Collect the resulting line of data and pass it to plug_log.
          */
+        { // WINSCP
         size_t msglen = bufchain_size(buf);
         assert(msglen < ~(size_t)0);
         msg = snewn(msglen+1, char);
@@ -104,6 +105,7 @@ void log_proxy_stderr(Plug *plug, bufchain *buf, const void *vdata, size_t len)
          * Advance past the newline.
          */
         pos += nlpos+1 - (data + pos);
+        } // WINSCP
     }
 
     /*

+ 2 - 0
source/putty/import.c

@@ -683,6 +683,7 @@ static ssh2_userkey *openssh_pem_read(
 
         put_stringz(blob, key->keytype == OP_DSA ? "ssh-dss" : "ssh-rsa");
 
+        { // WINSCP
         ptrlen rsa_modulus = PTRLEN_LITERAL("");
 
         for (i = 0; i < num_integers; i++) {
@@ -749,6 +750,7 @@ static ssh2_userkey *openssh_pem_read(
             errmsg = "unable to create key data structure";
             goto error;
         }
+        } // WINSCP
 
     } else {
         unreachable("Bad key type from load_openssh_pem_key");

+ 32 - 27
source/putty/misc.h

@@ -258,14 +258,15 @@ static inline uint64_t GET_64BIT_LSB_FIRST(const void *vp)
 static inline void PUT_64BIT_LSB_FIRST(void *vp, uint64_t value)
 {
     uint8_t *p = (uint8_t *)vp;
-    p[0] = value;
-    p[1] = (value) >> 8;
-    p[2] = (value) >> 16;
-    p[3] = (value) >> 24;
-    p[4] = (value) >> 32;
-    p[5] = (value) >> 40;
-    p[6] = (value) >> 48;
-    p[7] = (value) >> 56;
+    // WINSCP cast to uint8_t
+    p[0] = (uint8_t)value;
+    p[1] = (uint8_t)((value) >> 8);
+    p[2] = (uint8_t)((value) >> 16);
+    p[3] = (uint8_t)((value) >> 24);
+    p[4] = (uint8_t)((value) >> 32);
+    p[5] = (uint8_t)((value) >> 40);
+    p[6] = (uint8_t)((value) >> 48);
+    p[7] = (uint8_t)((value) >> 56);
 }
 
 static inline uint32_t GET_32BIT_LSB_FIRST(const void *vp)
@@ -278,10 +279,11 @@ static inline uint32_t GET_32BIT_LSB_FIRST(const void *vp)
 static inline void PUT_32BIT_LSB_FIRST(void *vp, uint32_t value)
 {
     uint8_t *p = (uint8_t *)vp;
-    p[0] = value;
-    p[1] = (value) >> 8;
-    p[2] = (value) >> 16;
-    p[3] = (value) >> 24;
+    // WINSCP cast to uint8_t
+    p[0] = (uint8_t)value;
+    p[1] = (uint8_t)((value) >> 8);
+    p[2] = (uint8_t)((value) >> 16);
+    p[3] = (uint8_t)((value) >> 24);
 }
 
 static inline uint16_t GET_16BIT_LSB_FIRST(const void *vp)
@@ -293,8 +295,9 @@ static inline uint16_t GET_16BIT_LSB_FIRST(const void *vp)
 static inline void PUT_16BIT_LSB_FIRST(void *vp, uint16_t value)
 {
     uint8_t *p = (uint8_t *)vp;
-    p[0] = value;
-    p[1] = (value) >> 8;
+    // WINSCP cast to uint8_t
+    p[0] = (uint8_t)value;
+    p[1] = (uint8_t)((value) >> 8);
 }
 
 static inline uint64_t GET_64BIT_MSB_FIRST(const void *vp)
@@ -309,14 +312,15 @@ static inline uint64_t GET_64BIT_MSB_FIRST(const void *vp)
 static inline void PUT_64BIT_MSB_FIRST(void *vp, uint64_t value)
 {
     uint8_t *p = (uint8_t *)vp;
-    p[7] = value;
-    p[6] = (value) >> 8;
-    p[5] = (value) >> 16;
-    p[4] = (value) >> 24;
-    p[3] = (value) >> 32;
-    p[2] = (value) >> 40;
-    p[1] = (value) >> 48;
-    p[0] = (value) >> 56;
+    // WINSCP cast to uint8_t
+    p[7] = (uint8_t)value;
+    p[6] = (uint8_t)((value) >> 8);
+    p[5] = (uint8_t)((value) >> 16);
+    p[4] = (uint8_t)((value) >> 24);
+    p[3] = (uint8_t)((value) >> 32);
+    p[2] = (uint8_t)((value) >> 40);
+    p[1] = (uint8_t)((value) >> 48);
+    p[0] = (uint8_t)((value) >> 56);
 }
 
 static inline uint32_t GET_32BIT_MSB_FIRST(const void *vp)
@@ -329,10 +333,11 @@ static inline uint32_t GET_32BIT_MSB_FIRST(const void *vp)
 static inline void PUT_32BIT_MSB_FIRST(void *vp, uint32_t value)
 {
     uint8_t *p = (uint8_t *)vp;
-    p[3] = value;
-    p[2] = (value) >> 8;
-    p[1] = (value) >> 16;
-    p[0] = (value) >> 24;
+    // WINSCP cast to uint8_t
+    p[3] = (uint8_t)value;
+    p[2] = (uint8_t)((value) >> 8);
+    p[1] = (uint8_t)((value) >> 16);
+    p[0] = (uint8_t)((value) >> 24);
 }
 
 static inline uint16_t GET_16BIT_MSB_FIRST(const void *vp)
@@ -344,7 +349,7 @@ static inline uint16_t GET_16BIT_MSB_FIRST(const void *vp)
 static inline void PUT_16BIT_MSB_FIRST(void *vp, uint16_t value)
 {
     uint8_t *p = (uint8_t *)vp;
-    p[1] = value;
+    p[1] = (uint8_t)value;
     p[0] = (value) >> 8;
 }
 

+ 8 - 4
source/putty/mpint.c

@@ -733,7 +733,8 @@ void mp_sub_into(mp_int *r, mp_int *a, mp_int *b)
 
 void mp_and_into(mp_int *r, mp_int *a, mp_int *b)
 {
-    for (size_t i = 0; i < r->nw; i++) {
+    size_t i; // WINSCP
+    for (i = 0; i < r->nw; i++) {
         BignumInt aword = mp_word(a, i), bword = mp_word(b, i);
         r->w[i] = aword & bword;
     }
@@ -741,7 +742,8 @@ void mp_and_into(mp_int *r, mp_int *a, mp_int *b)
 
 void mp_or_into(mp_int *r, mp_int *a, mp_int *b)
 {
-    for (size_t i = 0; i < r->nw; i++) {
+    size_t i; // WINSCP
+    for (i = 0; i < r->nw; i++) {
         BignumInt aword = mp_word(a, i), bword = mp_word(b, i);
         r->w[i] = aword | bword;
     }
@@ -749,7 +751,8 @@ void mp_or_into(mp_int *r, mp_int *a, mp_int *b)
 
 void mp_xor_into(mp_int *r, mp_int *a, mp_int *b)
 {
-    for (size_t i = 0; i < r->nw; i++) {
+    size_t i; // WINSCP
+    for (i = 0; i < r->nw; i++) {
         BignumInt aword = mp_word(a, i), bword = mp_word(b, i);
         r->w[i] = aword ^ bword;
     }
@@ -757,7 +760,8 @@ void mp_xor_into(mp_int *r, mp_int *a, mp_int *b)
 
 void mp_bic_into(mp_int *r, mp_int *a, mp_int *b)
 {
-    for (size_t i = 0; i < r->nw; i++) {
+    size_t i; // WINSCP
+    for (i = 0; i < r->nw; i++) {
         BignumInt aword = mp_word(a, i), bword = mp_word(b, i);
         r->w[i] = aword & ~bword;
     }

+ 2 - 0
source/putty/ssh.c

@@ -324,6 +324,7 @@ static void ssh_check_frozen(Ssh *ssh)
     if (!ssh->s)
         return;
 
+    { // WINSCP
     bool prev_frozen = ssh->socket_frozen;
     ssh->socket_frozen = (ssh->logically_frozen ||
                           bufchain_size(&ssh->in_raw) > SSH_MAX_BACKLOG);
@@ -335,6 +336,7 @@ static void ssh_check_frozen(Ssh *ssh)
          */
         queue_idempotent_callback(&ssh->bpp->ic_in_raw);
     }
+    } // WINSCP
 }
 
 void ssh_conn_processed_data(Ssh *ssh)

+ 2 - 0
source/putty/sshdss.c

@@ -136,6 +136,7 @@ static bool dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
     }
 
     /* Basic sanity checks: 0 < r,s < q */
+    { // WINSCP
     unsigned invalid = 0;
     invalid |= mp_eq_integer(r, 0);
     invalid |= mp_eq_integer(s, 0);
@@ -198,6 +199,7 @@ static bool dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
     } // WINSCP
     } // WINSCP
     } // WINSCP
+    } // WINSCP
 
     return toret;
 }

+ 1 - 1
source/putty/sshpubk.c

@@ -1525,7 +1525,7 @@ char *ssh2_fingerprint_blob(ptrlen blob)
     for (i = 0; i < 16; i++)
         sprintf(fingerprint_str_md5 + i*3, "%02x%s", digest[i], i==15 ? "" : ":");
 
-    hash_simple(&ssh_sha256, make_ptrlen(blob, bloblen), digest);
+    hash_simple(&ssh_sha256, blob, digest);
     base64_encode_buf(digest, 32, fingerprint_str_sha256);
 
     /*

+ 2 - 1
source/putty/utils.c

@@ -796,7 +796,8 @@ void sanitise_term_data(bufchain *out, const void *vdata, size_t len)
      * (not to mention knowing what character set it should interpret
      * the data as).
      */
-    for (size_t i = 0; i < len; i++) {
+    size_t i; // WINSCP
+    for (i = 0; i < len; i++) {
         if (data[i] == '\n')
             bufchain_add(out, "\r\n", 2);
         else if (data[i] >= ' ' && data[i] < 0x7F)

+ 2 - 0
source/putty/windows/winhsock.c

@@ -196,6 +196,7 @@ static void handle_socket_unfreeze(void *hsv)
     /*
      * Get some of the data we've buffered.
      */
+    { // WINSCP
     ptrlen data = bufchain_prefix(&hs->inputdata);
     assert(data.len > 0);
 
@@ -225,6 +226,7 @@ static void handle_socket_unfreeze(void *hsv)
         hs->frozen = UNFROZEN;
         handle_unthrottle(hs->recv_h, 0);
     }
+    } // WINSCP
 }
 
 static void sk_handle_set_frozen(Socket *s, bool is_frozen)

+ 2 - 0
source/putty/windows/winnet.c

@@ -1496,9 +1496,11 @@ void try_send(NetSocket *s)
 	    data = &s->oobdata;
 	} else {
 	    urgentflag = 0;
+            { // WINSCP
             ptrlen bufdata = bufchain_prefix(&s->output_data);
             data = bufdata.ptr;
             len = bufdata.len;
+            } // WINSCP
 	}
         len = min(len, INT_MAX);       /* WinSock send() takes an int */
 	nsent = p_send(s->s, data, len, urgentflag);