summaryrefslogtreecommitdiff
path: root/ssh-keyscan.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2002-07-07 22:17:22 +0000
committerBen Lindstrom <mouring@eviladmin.org>2002-07-07 22:17:22 +0000
commit965710f66e05f970a107a7636bc7a6b437736d0d (patch)
tree784bd2d61acd1369e6aafbab16d58613eb41e7fc /ssh-keyscan.c
parent8e8ef2a3ffb03d48bb9d6b894152497810f19044 (diff)
- deraadt@cvs.openbsd.org 2002/07/06 01:01:26
[ssh-keyscan.c] KNF, realloc fix, and clean usage
Diffstat (limited to 'ssh-keyscan.c')
-rw-r--r--ssh-keyscan.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/ssh-keyscan.c b/ssh-keyscan.c
index cd8b63488..7210aa387 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.38 2002/06/27 19:49:08 stevesk Exp $"); 10RCSID("$OpenBSD: ssh-keyscan.c,v 1.39 2002/07/06 01:01:26 deraadt Exp $");
11 11
12#include "openbsd-compat/fake-queue.h" 12#include "openbsd-compat/fake-queue.h"
13 13
@@ -171,14 +171,16 @@ Linebuf_lineno(Linebuf * lb)
171static char * 171static char *
172Linebuf_getline(Linebuf * lb) 172Linebuf_getline(Linebuf * lb)
173{ 173{
174 u_int size;
174 int n = 0; 175 int n = 0;
176 void *p;
175 177
176 lb->lineno++; 178 lb->lineno++;
177 for (;;) { 179 for (;;) {
178 /* Read a line */ 180 /* Read a line */
179 if (!fgets(&lb->buf[n], lb->size - n, lb->stream)) { 181 if (!fgets(&lb->buf[n], lb->size - n, lb->stream)) {
180 if (ferror(lb->stream) && lb->errfun) 182 if (ferror(lb->stream) && lb->errfun)
181 (*lb->errfun) ("%s: %s\n", lb->filename, 183 (*lb->errfun)("%s: %s\n", lb->filename,
182 strerror(errno)); 184 strerror(errno));
183 return (NULL); 185 return (NULL);
184 } 186 }
@@ -191,17 +193,20 @@ Linebuf_getline(Linebuf * lb)
191 } 193 }
192 if (n != lb->size - 1) { 194 if (n != lb->size - 1) {
193 if (lb->errfun) 195 if (lb->errfun)
194 (*lb->errfun) ("%s: skipping incomplete last line\n", 196 (*lb->errfun)("%s: skipping incomplete last line\n",
195 lb->filename); 197 lb->filename);
196 return (NULL); 198 return (NULL);
197 } 199 }
198 /* Double the buffer if we need more space */ 200 /* Double the buffer if we need more space */
199 if (!(lb->buf = realloc(lb->buf, (lb->size *= 2)))) { 201 lb->size *= 2;
202 if ((p = realloc(lb->buf, lb->size)) == NULL) {
203 lb->size /= 2;
200 if (lb->errfun) 204 if (lb->errfun)
201 (*lb->errfun) ("linebuf (%s): realloc failed\n", 205 (*lb->errfun)("linebuf (%s): realloc failed\n",
202 lb->filename); 206 lb->filename);
203 return (NULL); 207 return (NULL);
204 } 208 }
209 lb->buf = p;
205 } 210 }
206} 211}
207 212
@@ -412,8 +417,8 @@ tcpconnect(char *host)
412static int 417static int
413conalloc(char *iname, char *oname, int keytype) 418conalloc(char *iname, char *oname, int keytype)
414{ 419{
415 int s;
416 char *namebase, *name, *namelist; 420 char *namebase, *name, *namelist;
421 int s;
417 422
418 namebase = namelist = xstrdup(iname); 423 namebase = namelist = xstrdup(iname);
419 424
@@ -477,8 +482,8 @@ contouch(int s)
477static int 482static int
478conrecycle(int s) 483conrecycle(int s)
479{ 484{
480 int ret;
481 con *c = &fdcon[s]; 485 con *c = &fdcon[s];
486 int ret;
482 487
483 ret = conalloc(c->c_namelist, c->c_output_name, c->c_keytype); 488 ret = conalloc(c->c_namelist, c->c_output_name, c->c_keytype);
484 confree(s); 489 confree(s);
@@ -488,10 +493,10 @@ conrecycle(int s)
488static void 493static void
489congreet(int s) 494congreet(int s)
490{ 495{
496 int remote_major, remote_minor, n = 0;
491 char buf[256], *cp; 497 char buf[256], *cp;
492 char remote_version[sizeof buf]; 498 char remote_version[sizeof buf];
493 size_t bufsiz; 499 size_t bufsiz;
494 int remote_major, remote_minor, n = 0;
495 con *c = &fdcon[s]; 500 con *c = &fdcon[s];
496 501
497 bufsiz = sizeof(buf); 502 bufsiz = sizeof(buf);
@@ -555,8 +560,8 @@ congreet(int s)
555static void 560static void
556conread(int s) 561conread(int s)
557{ 562{
558 int n;
559 con *c = &fdcon[s]; 563 con *c = &fdcon[s];
564 int n;
560 565
561 if (c->c_status == CS_CON) { 566 if (c->c_status == CS_CON) {
562 congreet(s); 567 congreet(s);
@@ -595,10 +600,10 @@ conread(int s)
595static void 600static void
596conloop(void) 601conloop(void)
597{ 602{
598 fd_set *r, *e;
599 struct timeval seltime, now; 603 struct timeval seltime, now;
600 int i; 604 fd_set *r, *e;
601 con *c; 605 con *c;
606 int i;
602 607
603 gettimeofday(&now, NULL); 608 gettimeofday(&now, NULL);
604 c = TAILQ_FIRST(&tq); 609 c = TAILQ_FIRST(&tq);
@@ -665,6 +670,7 @@ void
665fatal(const char *fmt,...) 670fatal(const char *fmt,...)
666{ 671{
667 va_list args; 672 va_list args;
673
668 va_start(args, fmt); 674 va_start(args, fmt);
669 do_log(SYSLOG_LEVEL_FATAL, fmt, args); 675 do_log(SYSLOG_LEVEL_FATAL, fmt, args);
670 va_end(args); 676 va_end(args);
@@ -677,16 +683,9 @@ fatal(const char *fmt,...)
677static void 683static void
678usage(void) 684usage(void)
679{ 685{
680 fprintf(stderr, "Usage: %s [options] host ...\n", 686 fprintf(stderr, "usage: %s [-v46] [-p port] [-T timeout] [-f file]\n"
687 "\t\t [host | addrlist namelist] [...]\n",
681 __progname); 688 __progname);
682 fprintf(stderr, "Options:\n");
683 fprintf(stderr, " -f file Read hosts or addresses from file.\n");
684 fprintf(stderr, " -p port Connect to the specified port.\n");
685 fprintf(stderr, " -t keytype Specify the host key type.\n");
686 fprintf(stderr, " -T timeout Set connection timeout.\n");
687 fprintf(stderr, " -v Verbose; display verbose debugging messages.\n");
688 fprintf(stderr, " -4 Use IPv4 only.\n");
689 fprintf(stderr, " -6 Use IPv6 only.\n");
690 exit(1); 689 exit(1);
691} 690}
692 691