summaryrefslogtreecommitdiff
path: root/ssh-keyscan.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2009-12-29 21:32:03 +0000
committerColin Watson <cjwatson@debian.org>2009-12-29 21:32:03 +0000
commit04942aa41fa94ec6f2c3ce1d348f600f31bb7c78 (patch)
treeaf8e928bd79d3f2d0219bb5b2c78b573ec31d94c /ssh-keyscan.c
parent9ad7b718d42e43f3a285fcbc8f91193931fce324 (diff)
parent16704d57999d987fb8d9ba53379841a79f016d67 (diff)
import openssh-4.2p1-gsskex-20050926-2.patch
Diffstat (limited to 'ssh-keyscan.c')
-rw-r--r--ssh-keyscan.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/ssh-keyscan.c b/ssh-keyscan.c
index bc2c3b728..46f063687 100644
--- a/ssh-keyscan.c
+++ b/ssh-keyscan.c
@@ -7,7 +7,7 @@
7 */ 7 */
8 8
9#include "includes.h" 9#include "includes.h"
10RCSID("$OpenBSD: ssh-keyscan.c,v 1.52 2005/03/01 15:47:14 jmc Exp $"); 10RCSID("$OpenBSD: ssh-keyscan.c,v 1.55 2005/06/17 02:44:33 djm Exp $");
11 11
12#include "openbsd-compat/sys-queue.h" 12#include "openbsd-compat/sys-queue.h"
13 13
@@ -166,7 +166,7 @@ Linebuf_lineno(Linebuf * lb)
166static char * 166static char *
167Linebuf_getline(Linebuf * lb) 167Linebuf_getline(Linebuf * lb)
168{ 168{
169 int n = 0; 169 size_t n = 0;
170 void *p; 170 void *p;
171 171
172 lb->lineno++; 172 lb->lineno++;
@@ -493,7 +493,7 @@ conrecycle(int s)
493static void 493static void
494congreet(int s) 494congreet(int s)
495{ 495{
496 int remote_major = 0, remote_minor = 0, n = 0; 496 int n = 0, remote_major = 0, remote_minor = 0;
497 char buf[256], *cp; 497 char buf[256], *cp;
498 char remote_version[sizeof buf]; 498 char remote_version[sizeof buf];
499 size_t bufsiz; 499 size_t bufsiz;
@@ -506,14 +506,17 @@ congreet(int s)
506 *cp = '\n'; 506 *cp = '\n';
507 cp++; 507 cp++;
508 } 508 }
509 if (n < 0) {
510 if (errno != ECONNREFUSED)
511 error("read (%s): %s", c->c_name, strerror(errno));
512 conrecycle(s);
513 return;
514 }
515 if (n == 0) { 509 if (n == 0) {
516 error("%s: Connection closed by remote host", c->c_name); 510 switch (errno) {
511 case EPIPE:
512 error("%s: Connection closed by remote host", c->c_name);
513 break;
514 case ECONNREFUSED:
515 break;
516 default:
517 error("read (%s): %s", c->c_name, strerror(errno));
518 break;
519 }
517 conrecycle(s); 520 conrecycle(s);
518 return; 521 return;
519 } 522 }
@@ -543,7 +546,12 @@ congreet(int s)
543 n = snprintf(buf, sizeof buf, "SSH-%d.%d-OpenSSH-keyscan\r\n", 546 n = snprintf(buf, sizeof buf, "SSH-%d.%d-OpenSSH-keyscan\r\n",
544 c->c_keytype == KT_RSA1? PROTOCOL_MAJOR_1 : PROTOCOL_MAJOR_2, 547 c->c_keytype == KT_RSA1? PROTOCOL_MAJOR_1 : PROTOCOL_MAJOR_2,
545 c->c_keytype == KT_RSA1? PROTOCOL_MINOR_1 : PROTOCOL_MINOR_2); 548 c->c_keytype == KT_RSA1? PROTOCOL_MINOR_1 : PROTOCOL_MINOR_2);
546 if (atomicio(vwrite, s, buf, n) != n) { 549 if (n < 0 || (size_t)n >= sizeof(buf)) {
550 error("snprintf: buffer too small");
551 confree(s);
552 return;
553 }
554 if (atomicio(vwrite, s, buf, n) != (size_t)n) {
547 error("write (%s): %s", c->c_name, strerror(errno)); 555 error("write (%s): %s", c->c_name, strerror(errno));
548 confree(s); 556 confree(s);
549 return; 557 return;
@@ -561,14 +569,14 @@ static void
561conread(int s) 569conread(int s)
562{ 570{
563 con *c = &fdcon[s]; 571 con *c = &fdcon[s];
564 int n; 572 size_t n;
565 573
566 if (c->c_status == CS_CON) { 574 if (c->c_status == CS_CON) {
567 congreet(s); 575 congreet(s);
568 return; 576 return;
569 } 577 }
570 n = atomicio(read, s, c->c_data + c->c_off, c->c_len - c->c_off); 578 n = atomicio(read, s, c->c_data + c->c_off, c->c_len - c->c_off);
571 if (n < 0) { 579 if (n == 0) {
572 error("read (%s): %s", c->c_name, strerror(errno)); 580 error("read (%s): %s", c->c_name, strerror(errno));
573 confree(s); 581 confree(s);
574 return; 582 return;