summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2005-10-30 04:01:04 +0000
committerDamien Miller <djm@cvs.openbsd.org>2005-10-30 04:01:04 +0000
commit4361b30e4b3e91ef724b440897ad83dc1335fe8d (patch)
tree05ed0b526060dbb92528093a84b483d97ee429ac
parent54928787bdbff9eb28b8782e38ebbf4ae506fa05 (diff)
make ssh-keygen discard junk from server before SSH- ident, spotted by
dave AT cirt.net; ok dtucker@
-rw-r--r--usr.bin/ssh/ssh-keyscan.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/usr.bin/ssh/ssh-keyscan.c b/usr.bin/ssh/ssh-keyscan.c
index 634184723e2..ac897089aa1 100644
--- a/usr.bin/ssh/ssh-keyscan.c
+++ b/usr.bin/ssh/ssh-keyscan.c
@@ -7,7 +7,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: ssh-keyscan.c,v 1.56 2005/09/13 23:40:07 djm Exp $");
+RCSID("$OpenBSD: ssh-keyscan.c,v 1.57 2005/10/30 04:01:03 djm Exp $");
#include <sys/queue.h>
#include <errno.h>
@@ -490,12 +490,18 @@ congreet(int s)
size_t bufsiz;
con *c = &fdcon[s];
- bufsiz = sizeof(buf);
- cp = buf;
- while (bufsiz-- && (n = atomicio(read, s, cp, 1)) == 1 && *cp != '\n') {
- if (*cp == '\r')
- *cp = '\n';
- cp++;
+ for (;;) {
+ memset(buf, '\0', sizeof(buf));
+ bufsiz = sizeof(buf);
+ cp = buf;
+ while (bufsiz-- &&
+ (n = atomicio(read, s, cp, 1)) == 1 && *cp != '\n') {
+ if (*cp == '\r')
+ *cp = '\n';
+ cp++;
+ }
+ if (n != 1 || strncmp(buf, "SSH-", 4) == 0)
+ break;
}
if (n == 0) {
switch (errno) {