jonathancammack / rpms / openssh

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