jonathancammack / rpms / openssh

Forked from rpms/openssh 8 months ago
Clone
338224
diff --git a/ssh-keyscan.c b/ssh-keyscan.c
338224
index d29a03b4..d7283136 100644
338224
--- a/ssh-keyscan.c
338224
+++ b/ssh-keyscan.c
338224
@@ -490,6 +490,15 @@ congreet(int s)
338224
 		return;
338224
 	}
338224
 
338224
+	/*
338224
+	 * Read the server banner as per RFC4253 section 4.2.  The "SSH-"
338224
+	 * protocol identification string may be preceeded by an arbitarily
338224
+	 * large banner which we must read and ignore.  Loop while reading
338224
+	 * newline-terminated lines until we have one starting with "SSH-".
338224
+	 * The ID string cannot be longer than 255 characters although the
338224
+	 * preceeding banner lines may (in which case they'll be discarded
338224
+	 * in multiple iterations of the outer loop).
338224
+	 */
338224
 	for (;;) {
338224
 		memset(buf, '\0', sizeof(buf));
338224
 		bufsiz = sizeof(buf);
338224
@@ -517,6 +526,11 @@ congreet(int s)
338224
 		conrecycle(s);
338224
 		return;
338224
 	}
338224
+	if (cp >= buf + sizeof(buf)) {
338224
+		error("%s: greeting exceeds allowable length", c->c_name);
338224
+		confree(s);
338224
+		return;
338224
+	}
338224
 	if (*cp != '\n' && *cp != '\r') {
338224
 		error("%s: bad greeting", c->c_name);
338224
 		confree(s);