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 cd8b6348..7210aa38 100644
--- a/ssh-keyscan.c
+++ b/ssh-keyscan.c
@@ -7,7 +7,7 @@
*/
#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"
@@ -171,14 +171,16 @@ Linebuf_lineno(Linebuf * lb)
static char *
Linebuf_getline(Linebuf * lb)
{
+ u_int size;
int n = 0;
+ void *p;
lb->lineno++;
for (;;) {
/* Read a line */
if (!fgets(&lb->buf[n], lb->size - n, lb->stream)) {
if (ferror(lb->stream) && lb->errfun)
- (*lb->errfun) ("%s: %s\n", lb->filename,
+ (*lb->errfun)("%s: %s\n", lb->filename,
strerror(errno));
return (NULL);
}
@@ -191,17 +193,20 @@ Linebuf_getline(Linebuf * lb)
}
if (n != lb->size - 1) {
if (lb->errfun)
- (*lb->errfun) ("%s: skipping incomplete last line\n",
+ (*lb->errfun)("%s: skipping incomplete last line\n",
lb->filename);
return (NULL);
}
/* 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)
- (*lb->errfun) ("linebuf (%s): realloc failed\n",
+ (*lb->errfun)("linebuf (%s): realloc failed\n",
lb->filename);
return (NULL);
}
+ lb->buf = p;
}
}
@@ -412,8 +417,8 @@ tcpconnect(char *host)
static int
conalloc(char *iname, char *oname, int keytype)
{
- int s;
char *namebase, *name, *namelist;
+ int s;
namebase = namelist = xstrdup(iname);
@@ -477,8 +482,8 @@ contouch(int s)
static int
conrecycle(int s)
{
- int ret;
con *c = &fdcon[s];
+ int ret;
ret = conalloc(c->c_namelist, c->c_output_name, c->c_keytype);
confree(s);
@@ -488,10 +493,10 @@ conrecycle(int s)
static void
congreet(int s)
{
+ int remote_major, remote_minor, n = 0;
char buf[256], *cp;
char remote_version[sizeof buf];
size_t bufsiz;
- int remote_major, remote_minor, n = 0;
con *c = &fdcon[s];
bufsiz = sizeof(buf);
@@ -555,8 +560,8 @@ congreet(int s)
static void
conread(int s)
{
- int n;
con *c = &fdcon[s];
+ int n;
if (c->c_status == CS_CON) {
congreet(s);
@@ -595,10 +600,10 @@ conread(int s)
static void
conloop(void)
{
- fd_set *r, *e;
struct timeval seltime, now;
- int i;
+ fd_set *r, *e;
con *c;
+ int i;
gettimeofday(&now, NULL);
c = TAILQ_FIRST(&tq);
@@ -665,6 +670,7 @@ void
fatal(const char *fmt,...)
{
va_list args;
+
va_start(args, fmt);
do_log(SYSLOG_LEVEL_FATAL, fmt, args);
va_end(args);
@@ -677,16 +683,9 @@ fatal(const char *fmt,...)
static 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);
- 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);
}