]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
draft-ietf-secsh-transport-24 says that only "SSH-" at the start of a line
authorBen Harris <bjh21@bjh21.me.uk>
Sun, 24 Jul 2005 13:46:14 +0000 (13:46 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Sun, 24 Jul 2005 13:46:14 +0000 (13:46 +0000)
marks a version string.  It's a bit vague about the definition of a line,
but I think it's reasonable to assume that they'll end with LF.  Change
do_ssh_init() to ignore "SSH-" anywhere else.  This makes the existing state
machine overkill, so replace it with something a little more readable.

[originally from svn r6138]

ssh.c

diff --git a/ssh.c b/ssh.c
index a9bed27a48fa932b081edc41da58f3beffe041b0..2b2b1dc5edc4d36d7a4075593ae5a414159ae914 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -2295,23 +2295,20 @@ static int do_ssh_init(Ssh ssh, unsigned char c)
 
     crBegin(ssh->do_ssh_init_crstate);
 
-    /* Search for the string "SSH-" in the input. */
-    s->i = 0;
-    while (1) {
-       static const int transS[] = { 1, 2, 2, 1 };
-       static const int transH[] = { 0, 0, 3, 0 };
-       static const int transminus[] = { 0, 0, 0, -1 };
-       if (c == 'S')
-           s->i = transS[s->i];
-       else if (c == 'H')
-           s->i = transH[s->i];
-       else if (c == '-')
-           s->i = transminus[s->i];
-       else
-           s->i = 0;
-       if (s->i < 0)
-           break;
-       crReturn(1);                   /* get another character */
+    /* Search for a line beginning with the string "SSH-" in the input. */
+    for (;;) {
+       if (c != 'S') goto no;
+       crReturn(1);
+       if (c != 'S') goto no;
+       crReturn(1);
+       if (c != 'H') goto no;
+       crReturn(1);
+       if (c != '-') goto no;
+       break;
+      no:
+       while (c != '\012')
+           crReturn(1);
+       crReturn(1);
     }
 
     s->vstrsize = 16;