summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-03-06 01:06:04 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-03-06 01:06:04 +0000
commit9ec2df8ae20cfe39a5c661dc5124651a09331dd7 (patch)
tree2067172514ce4e09720544636eedc67ca3ca0b6c
parent5fb1ee3f97289074584bb6049f3126172b2e03be (diff)
Don't assume we wil get the version string all in one read().
deraadt@ OK'd
-rw-r--r--usr.bin/ssh/ssh-keyscan.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/usr.bin/ssh/ssh-keyscan.c b/usr.bin/ssh/ssh-keyscan.c
index 6f2ba0b48b8..cab158cb0fb 100644
--- a/usr.bin/ssh/ssh-keyscan.c
+++ b/usr.bin/ssh/ssh-keyscan.c
@@ -8,7 +8,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: ssh-keyscan.c,v 1.20 2001/03/05 15:37:27 deraadt Exp $");
+RCSID("$OpenBSD: ssh-keyscan.c,v 1.21 2001/03/06 01:06:03 millert Exp $");
#include <sys/queue.h>
#include <errno.h>
@@ -391,23 +391,27 @@ conrecycle(int s)
void
congreet(int s)
{
- char buf[80];
+ char buf[80], *cp;
+ size_t bufsiz;
int n;
con *c = &fdcon[s];
- n = read(s, buf, sizeof(buf));
+ bufsiz = sizeof(buf);
+ cp = buf;
+ while (bufsiz-- && (n = read(s, cp, 1)) == 1 && *cp != '\n' && *cp != '\r')
+ cp++;
if (n < 0) {
if (errno != ECONNREFUSED)
error("read (%s): %s", c->c_name, strerror(errno));
conrecycle(s);
return;
}
- if (buf[n - 1] != '\n') {
+ if (*cp != '\n' && *cp != '\r') {
error("%s: bad greeting", c->c_name);
confree(s);
return;
}
- buf[n - 1] = '\0';
+ *cp = '\0';
fprintf(stderr, "# %s %s\n", c->c_name, buf);
n = snprintf(buf, sizeof buf, "SSH-1.5-OpenSSH-keyscan\r\n");
if (atomicio(write, s, buf, n) != n) {