Selaa lähdekoodia

Updating code to PuTTY d73a1716

Source commit: bbc55afa6c9c56c7eaadefecb5b3e918aec5a1e6
Martin Prikryl 6 vuotta sitten
vanhempi
sitoutus
aa8799137d

+ 3 - 0
source/Putty.cbproj

@@ -128,6 +128,9 @@
 		<CppCompile Include="putty\marshal.c">
 			<BuildOrder>55</BuildOrder>
 		</CppCompile>
+		<CppCompile Include="putty\memory.c">
+			<BuildOrder>73</BuildOrder>
+		</CppCompile>
 		<CppCompile Include="putty\misc.c">
 			<BuildOrder>26</BuildOrder>
 			<BuildOrder>14</BuildOrder>

+ 6 - 0
source/putty/misc.h

@@ -294,4 +294,10 @@ void debug_memdump(const void *buf, int len, bool L);
  * then safely say things like printf("%.*s", length, NULLTOEMPTY(ptr)) */
 #define NULLTOEMPTY(s) ((s)?(s):"")
 
+#ifdef MPEXT
+// Recent PuTTY code uses C99 standard that allows code before initialization.
+// Mostly that code are assertions. This assert implementation allows being used before code.
+#define pinitassert(P) const int __assert_dummy = 1/(P)
+#endif
+
 #endif

+ 0 - 6
source/putty/putty.h

@@ -2152,10 +2152,4 @@ void pktin_free_queue_callback(void *vctx);
 #define WINSCP_BOM "\xEF\xBB\xBF"
 #endif
 
-#ifdef MPEXT
-// Recent PuTTY code uses C99 standard that allows code before initialization.
-// Mostly that code are assertions. This assert implementation allows being used before code.
-#define pinitassert(P) const int __assert_dummy = 1/(P)
-#endif
-
 #endif

+ 4 - 1
source/putty/ssh2transport.c

@@ -945,14 +945,17 @@ static bool ssh2_scan_kexinits(
          */
         *n_server_hostkeys = 0;
 
+        { // WINSCP
         ptrlen list = slists[KEXLIST_HOSTKEY];
-        for (ptrlen word; get_commasep_word(&list, &word) ;) {
+        ptrlen word; // WINSCP
+        for (; get_commasep_word(&list, &word) ;) {
             for (i = 0; i < lenof(ssh2_hostkey_algs); i++)
                 if (ptrlen_eq_string(word, ssh2_hostkey_algs[i].alg->ssh_id)) {
                     server_hostkeys[(*n_server_hostkeys)++] = i;
                     break;
                 }
         }
+        } // WINSCP
     }
 
     return true;

+ 4 - 1
source/putty/ssh2userauth.c

@@ -585,11 +585,13 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                 /*
                  * Scan it for method identifiers we know about.
                  */
+                { // WINSCP
                 bool srv_pubkey = false, srv_passwd = false;
                 bool srv_keyb_inter = false, srv_gssapi = false;
                 bool srv_gssapi_keyex_auth = false;
 
-                for (ptrlen method; get_commasep_word(&methods, &method) ;) {
+                ptrlen method; // WINSCP
+                for (; get_commasep_word(&methods, &method) ;) {
                     if (ptrlen_eq_string(method, "publickey"))
                         srv_pubkey = true;
                     else if (ptrlen_eq_string(method, "password"))
@@ -616,6 +618,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
                     srv_gssapi_keyex_auth &&
                     s->shgss->libs->nlibraries > 0 && s->shgss->ctx;
 #endif
+                } // WINSCP
             }
 
             s->ppl.bpp->pls->actx = SSH2_PKTCTX_NOAUTH;

+ 6 - 1
source/putty/sshdss.c

@@ -59,12 +59,17 @@ static void append_hex_to_strbuf(strbuf *sb, Bignum *x)
     if (sb->len > 0)
         put_byte(sb, ',');
     put_data(sb, "0x", 2);
+    { // WINSCP
     int nibbles = (3 + bignum_bitcount(x)) / 4;
     if (nibbles < 1)
 	nibbles = 1;
+    { // WINSCP
     static const char hex[] = "0123456789abcdef";
-    for (int i = nibbles; i--;)
+    int i; // WINSCP
+    for (i = nibbles; i--;)
 	put_byte(sb, hex[(bignum_byte(x, i / 2) >> (4 * (i % 2))) & 0xF]);
+    } // WINSCP
+    } // WINSCP
 }
 
 static char *dss_cache_str(ssh_key *key)

+ 19 - 5
source/putty/sshrsa.c

@@ -326,12 +326,17 @@ static void append_hex_to_strbuf(strbuf *sb, Bignum *x)
     if (sb->len > 0)
         put_byte(sb, ',');
     put_data(sb, "0x", 2);
+    { // WINSCP
     int nibbles = (3 + bignum_bitcount(x)) / 4;
     if (nibbles < 1)
 	nibbles = 1;
+    { // WINSCP
     static const char hex[] = "0123456789abcdef";
-    for (int i = nibbles; i--;)
+    int i; // WINSCP
+    for (i = nibbles; i--;)
 	put_byte(sb, hex[(bignum_byte(x, i / 2) >> (4 * (i % 2))) & 0xF]);
+    } // WINSCP
+    } // WINSCP
 }
 
 char *rsastr_fmt(struct RSAKey *key)
@@ -713,8 +718,9 @@ static unsigned char *rsa_pkcs1_signature_string(
         asn1_prefix_size = sizeof(sha1_asn1_prefix);
     }
 
+    { // WINSCP
     size_t fixed_parts = halg->hlen + asn1_prefix_size + 2;
-    assert(nbytes >= fixed_parts);
+    pinitassert(nbytes >= fixed_parts);
     size_t padding = nbytes - fixed_parts;
 
     unsigned char *bytes = snewn(nbytes, unsigned char);
@@ -726,11 +732,14 @@ static unsigned char *rsa_pkcs1_signature_string(
 
     memcpy(bytes + 2 + padding, asn1_prefix, asn1_prefix_size);
 
+    { // WINSCP
     ssh_hash *h = ssh_hash_new(halg);
     put_data(h, data.ptr, data.len);
     ssh_hash_final(h, bytes + 2 + padding + asn1_prefix_size);
+    } // WINSCP
 
     return bytes;
+    } // WINSCP
 }
 
 static bool rsa2_verify(ssh_key *key, ptrlen sig, ptrlen data)
@@ -763,13 +772,16 @@ static bool rsa2_verify(ssh_key *key, ptrlen sig, ptrlen data)
 
     toret = true;
 
+    { // WINSCP
     size_t nbytes = (bignum_bitcount(rsa->modulus) + 7) / 8;
     unsigned char *bytes = rsa_pkcs1_signature_string(nbytes, &ssh_sha1, data);
-    for (size_t i = 0; i < nbytes; i++)
+    size_t i; // WINSCP
+    for (i = 0; i < nbytes; i++)
 	if (bytes[nbytes-1 - i] != bignum_byte(out, i))
 	    toret = false;
     smemclr(bytes, nbytes);
     sfree(bytes);
+    } // WINSCP
     freebn(out);
 
     return toret;
@@ -810,9 +822,11 @@ static void rsa2_sign(ssh_key *key, const void *data, int datalen,
     put_stringz(bs, sign_alg_name);
     nbytes = (bignum_bitcount(out) + 7) / 8;
     put_uint32(bs, nbytes);
-    for (size_t i = 0; i < nbytes; i++)
-
+    { // WINSCP
+    size_t i; // WINSCP
+    for (i = 0; i < nbytes; i++)
 	put_byte(bs, bignum_byte(out, nbytes - 1 - i));
+    } // WINSCP
 
     freebn(out);
 }