From ae64be506fce3656d81ff416c0b77f75afc67c7c Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sun, 24 Jul 2005 13:46:14 +0000 Subject: [PATCH] draft-ietf-secsh-transport-24 says that only "SSH-" at the start of a line 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 | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/ssh.c b/ssh.c index a9bed27a..2b2b1dc5 100644 --- 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;