[ssh-keyscan.c]
     KNF, realloc fix, and clean usage
This commit is contained in:
Ben Lindstrom 2002-07-07 22:17:22 +00:00
parent 8e8ef2a3ff
commit 965710f66e
2 changed files with 23 additions and 21 deletions

View File

@ -19,6 +19,9 @@
- deraadt@cvs.openbsd.org 2002/07/06 01:00:49 - deraadt@cvs.openbsd.org 2002/07/06 01:00:49
[log.c] [log.c]
KNF KNF
- deraadt@cvs.openbsd.org 2002/07/06 01:01:26
[ssh-keyscan.c]
KNF, realloc fix, and clean usage
20020705 20020705
- (tim) [configure.ac] AIX 4.2.1 has authenticate() in libs. - (tim) [configure.ac] AIX 4.2.1 has authenticate() in libs.
@ -1302,4 +1305,4 @@
- (stevesk) entropy.c: typo in debug message - (stevesk) entropy.c: typo in debug message
- (djm) ssh-keygen -i needs seeded RNG; report from markus@ - (djm) ssh-keygen -i needs seeded RNG; report from markus@
$Id: ChangeLog,v 1.2345 2002/07/07 22:14:55 mouring Exp $ $Id: ChangeLog,v 1.2346 2002/07/07 22:17:22 mouring Exp $

View File

@ -7,7 +7,7 @@
*/ */
#include "includes.h" #include "includes.h"
RCSID("$OpenBSD: ssh-keyscan.c,v 1.38 2002/06/27 19:49:08 stevesk Exp $"); RCSID("$OpenBSD: ssh-keyscan.c,v 1.39 2002/07/06 01:01:26 deraadt Exp $");
#include "openbsd-compat/fake-queue.h" #include "openbsd-compat/fake-queue.h"
@ -171,7 +171,9 @@ Linebuf_lineno(Linebuf * lb)
static char * static char *
Linebuf_getline(Linebuf * lb) Linebuf_getline(Linebuf * lb)
{ {
u_int size;
int n = 0; int n = 0;
void *p;
lb->lineno++; lb->lineno++;
for (;;) { for (;;) {
@ -196,12 +198,15 @@ Linebuf_getline(Linebuf * lb)
return (NULL); return (NULL);
} }
/* Double the buffer if we need more space */ /* Double the buffer if we need more space */
if (!(lb->buf = realloc(lb->buf, (lb->size *= 2)))) { lb->size *= 2;
if ((p = realloc(lb->buf, lb->size)) == NULL) {
lb->size /= 2;
if (lb->errfun) if (lb->errfun)
(*lb->errfun)("linebuf (%s): realloc failed\n", (*lb->errfun)("linebuf (%s): realloc failed\n",
lb->filename); lb->filename);
return (NULL); return (NULL);
} }
lb->buf = p;
} }
} }
@ -412,8 +417,8 @@ tcpconnect(char *host)
static int static int
conalloc(char *iname, char *oname, int keytype) conalloc(char *iname, char *oname, int keytype)
{ {
int s;
char *namebase, *name, *namelist; char *namebase, *name, *namelist;
int s;
namebase = namelist = xstrdup(iname); namebase = namelist = xstrdup(iname);
@ -477,8 +482,8 @@ contouch(int s)
static int static int
conrecycle(int s) conrecycle(int s)
{ {
int ret;
con *c = &fdcon[s]; con *c = &fdcon[s];
int ret;
ret = conalloc(c->c_namelist, c->c_output_name, c->c_keytype); ret = conalloc(c->c_namelist, c->c_output_name, c->c_keytype);
confree(s); confree(s);
@ -488,10 +493,10 @@ conrecycle(int s)
static void static void
congreet(int s) congreet(int s)
{ {
int remote_major, remote_minor, n = 0;
char buf[256], *cp; char buf[256], *cp;
char remote_version[sizeof buf]; char remote_version[sizeof buf];
size_t bufsiz; size_t bufsiz;
int remote_major, remote_minor, n = 0;
con *c = &fdcon[s]; con *c = &fdcon[s];
bufsiz = sizeof(buf); bufsiz = sizeof(buf);
@ -555,8 +560,8 @@ congreet(int s)
static void static void
conread(int s) conread(int s)
{ {
int n;
con *c = &fdcon[s]; con *c = &fdcon[s];
int n;
if (c->c_status == CS_CON) { if (c->c_status == CS_CON) {
congreet(s); congreet(s);
@ -595,10 +600,10 @@ conread(int s)
static void static void
conloop(void) conloop(void)
{ {
fd_set *r, *e;
struct timeval seltime, now; struct timeval seltime, now;
int i; fd_set *r, *e;
con *c; con *c;
int i;
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
c = TAILQ_FIRST(&tq); c = TAILQ_FIRST(&tq);
@ -665,6 +670,7 @@ void
fatal(const char *fmt,...) fatal(const char *fmt,...)
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
do_log(SYSLOG_LEVEL_FATAL, fmt, args); do_log(SYSLOG_LEVEL_FATAL, fmt, args);
va_end(args); va_end(args);
@ -677,16 +683,9 @@ fatal(const char *fmt,...)
static void static void
usage(void) usage(void)
{ {
fprintf(stderr, "Usage: %s [options] host ...\n", fprintf(stderr, "usage: %s [-v46] [-p port] [-T timeout] [-f file]\n"
"\t\t [host | addrlist namelist] [...]\n",
__progname); __progname);
fprintf(stderr, "Options:\n");
fprintf(stderr, " -f file Read hosts or addresses from file.\n");
fprintf(stderr, " -p port Connect to the specified port.\n");
fprintf(stderr, " -t keytype Specify the host key type.\n");
fprintf(stderr, " -T timeout Set connection timeout.\n");
fprintf(stderr, " -v Verbose; display verbose debugging messages.\n");
fprintf(stderr, " -4 Use IPv4 only.\n");
fprintf(stderr, " -6 Use IPv6 only.\n");
exit(1); exit(1);
} }