]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Handle packets with no type byte by returning SSH_MSG_UNIMPLEMENTED.
authorBen Harris <bjh21@bjh21.me.uk>
Sat, 17 Oct 2015 20:00:31 +0000 (21:00 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Sat, 24 Oct 2015 21:45:48 +0000 (22:45 +0100)
The previous assertion failure is obviously wrong, but RFC 4253 doesn't
explicitly declare them to be a protocol error.  Currently, the incoming
packet isn't logged, which might cause some confusion for log parsers.

Bug found with the help of afl-fuzz.

ssh.c

diff --git a/ssh.c b/ssh.c
index cf4f0bfc77805d2b6f348dd89c0e80bf66d6fe92..1077209ae8e1fee800c0c0258db04da3b2742934 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -360,6 +360,7 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen,
                             struct Packet *pktin);
 static void ssh2_channel_check_close(struct ssh_channel *c);
 static void ssh_channel_destroy(struct ssh_channel *c);
+static void ssh2_msg_something_unimplemented(Ssh ssh, struct Packet *pktin);
 
 /*
  * Buffer management constants. There are several of these for
@@ -1742,6 +1743,15 @@ static struct Packet *ssh2_rdpkt(Ssh ssh, unsigned char **data, int *datalen)
        }
     }
 
+    /*
+     * RFC 4253 doesn't explicitly say that completely empty packets
+     * with no type byte are forbidden, so treat them as deserving
+     * an SSH_MSG_UNIMPLEMENTED.
+     */
+    if (st->pktin->length <= 5) { /* == 5 we hope, but robustness */
+        ssh2_msg_something_unimplemented(ssh, st->pktin);
+        crStop(NULL);
+    }
     /*
      * pktin->body and pktin->length should identify the semantic
      * content of the packet, excluding the initial type byte.