]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Security improvement: check CRC on incoming packets
authorSimon Tatham <anakin@pobox.com>
Wed, 31 May 2000 10:18:24 +0000 (10:18 +0000)
committerSimon Tatham <anakin@pobox.com>
Wed, 31 May 2000 10:18:24 +0000 (10:18 +0000)
[originally from svn r489]

ssh.c

diff --git a/ssh.c b/ssh.c
index a91190ec5aacb2fc061f5e0fb67d4035f4148795..295d0e68ba3989f9c454ea96ad66ca6d3defd240 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -127,6 +127,7 @@ static void ssh_gotdata(unsigned char *data, int datalen) {
     static long len, biglen, to_read;
     static unsigned char *p;
     static int i, pad;
+    static unsigned long realcrc, gotcrc;
 
     crBegin;
     while (1) {
@@ -186,6 +187,15 @@ static void ssh_gotdata(unsigned char *data, int datalen) {
        pktin.type = pktin.data[pad];
        pktin.body = pktin.data+pad+1;
 
+       realcrc = crc32(pktin.data, biglen-4);
+       gotcrc = (pktin.data[biglen-4] << 24);
+       gotcrc |= (pktin.data[biglen-3] << 16);
+       gotcrc |= (pktin.data[biglen-2] <<  8);
+       gotcrc |= (pktin.data[biglen-1] <<  0);
+       if (gotcrc != realcrc) {
+           fatalbox("Incorrect CRC received on packet");
+       }
+
        if (pktin.type == SSH_MSG_DEBUG) {
            /* FIXME: log it */
        } else if (pktin.type == SSH_MSG_IGNORE) {