bmh10 / rpms / openssh

Forked from rpms/openssh 10 days ago
Clone
2bc7a8
diff --git a/ssh-keyscan.c b/ssh-keyscan.c
2bc7a8
index d29a03b4..d7283136 100644
2bc7a8
--- a/ssh-keyscan.c
2bc7a8
+++ b/ssh-keyscan.c
2bc7a8
@@ -490,6 +490,15 @@ congreet(int s)
2bc7a8
 		return;
2bc7a8
 	}
2bc7a8
 
2bc7a8
+	/*
2bc7a8
+	 * Read the server banner as per RFC4253 section 4.2.  The "SSH-"
2bc7a8
+	 * protocol identification string may be preceeded by an arbitarily
2bc7a8
+	 * large banner which we must read and ignore.  Loop while reading
2bc7a8
+	 * newline-terminated lines until we have one starting with "SSH-".
2bc7a8
+	 * The ID string cannot be longer than 255 characters although the
2bc7a8
+	 * preceeding banner lines may (in which case they'll be discarded
2bc7a8
+	 * in multiple iterations of the outer loop).
2bc7a8
+	 */
2bc7a8
 	for (;;) {
2bc7a8
 		memset(buf, '\0', sizeof(buf));
2bc7a8
 		bufsiz = sizeof(buf);
2bc7a8
@@ -517,6 +526,11 @@ congreet(int s)
2bc7a8
 		conrecycle(s);
2bc7a8
 		return;
2bc7a8
 	}
2bc7a8
+	if (cp >= buf + sizeof(buf)) {
2bc7a8
+		error("%s: greeting exceeds allowable length", c->c_name);
2bc7a8
+		confree(s);
2bc7a8
+		return;
2bc7a8
+	}
2bc7a8
 	if (*cp != '\n' && *cp != '\r') {
2bc7a8
 		error("%s: bad greeting", c->c_name);
2bc7a8
 		confree(s);
2bc7a8
diff --git a/sshsig.c b/sshsig.c
2bc7a8
index 1e3b6398..eb2a931e 100644
2bc7a8
--- a/sshsig.c
2bc7a8
+++ b/sshsig.c
2bc7a8
@@ -491,7 +491,7 @@ hash_file(int fd, const char *hashalg, struct sshbuf **bp)
2bc7a8
 {
2bc7a8
 	char *hex, rbuf[8192], hash[SSH_DIGEST_MAX_LENGTH];
2bc7a8
 	ssize_t n, total = 0;
2bc7a8
-	struct ssh_digest_ctx *ctx;
2bc7a8
+	struct ssh_digest_ctx *ctx = NULL;
2bc7a8
 	int alg, oerrno, r = SSH_ERR_INTERNAL_ERROR;
2bc7a8
 	struct sshbuf *b = NULL;
2bc7a8
 
2bc7a8
@@ -549,9 +548,11 @@ hash_file(int fd, const char *hashalg, struct sshbuf **bp)
2bc7a8
 	/* success */
2bc7a8
 	r = 0;
2bc7a8
  out:
2bc7a8
+	oerrno = errno;
2bc7a8
 	sshbuf_free(b);
2bc7a8
 	ssh_digest_free(ctx);
2bc7a8
 	explicit_bzero(hash, sizeof(hash));
2bc7a8
+	errno = oerrno;
2bc7a8
 	return r;
2bc7a8
 }
2bc7a8