Fix bug in af_format where the formatted address was returned in the same

static buffer. When af_format is used more than once in the same printf
statement, the second call will overwrite the first. Changed af_format to
take a buffer and the buffer size where to place the formatted string.
This commit is contained in:
christos 1995-05-24 15:22:52 +00:00
parent caef1dfaa2
commit 1f1b61fc49
3 changed files with 56 additions and 24 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: af.c,v 1.7 1995/03/18 15:00:22 cgd Exp $ */
/* $NetBSD: af.c,v 1.8 1995/05/24 15:22:52 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)af.c 8.1 (Berkeley) 6/5/93";
#else
static char rcsid[] = "$NetBSD: af.c,v 1.7 1995/03/18 15:00:22 cgd Exp $";
static char rcsid[] = "$NetBSD: af.c,v 1.8 1995/05/24 15:22:52 christos Exp $";
#endif
#endif /* not lint */
@ -48,7 +48,7 @@ static char rcsid[] = "$NetBSD: af.c,v 1.7 1995/03/18 15:00:22 cgd Exp $";
*/
int inet_canon __P((struct sockaddr_in *));
int inet_checkhost __P((struct sockaddr_in *));
char *inet_format __P((struct sockaddr_in *));
char *inet_format __P((struct sockaddr_in *, char *buf, size_t sz));
int inet_hash __P((struct sockaddr_in *, struct afhash *));
int inet_netmatch __P((struct sockaddr_in *, struct sockaddr_in *));
int inet_portcheck __P((struct sockaddr_in *));
@ -180,10 +180,11 @@ inet_canon(sin)
}
char *
inet_format(sin)
inet_format(sin, buf, sz)
struct sockaddr_in *sin;
char *buf; size_t sz;
{
char *inet_ntoa();
return (inet_ntoa(sin->sin_addr));
strncpy(buf, inet_ntoa(sin->sin_addr), sz);
buf[sz - 1] = '\0';
return buf;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: input.c,v 1.11 1995/04/24 13:24:30 cgd Exp $ */
/* $NetBSD: input.c,v 1.12 1995/05/24 15:22:55 christos Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)input.c 8.1 (Berkeley) 6/5/93";
#else
static char rcsid[] = "$NetBSD: input.c,v 1.11 1995/04/24 13:24:30 cgd Exp $";
static char rcsid[] = "$NetBSD: input.c,v 1.12 1995/05/24 15:22:55 christos Exp $";
#endif
#endif /* not lint */
@ -63,6 +63,7 @@ rip_input(from, rip, size)
int count, changes = 0;
register struct afswitch *afp;
static struct sockaddr badfrom, badfrom2;
char buf1[256], buf2[256];
ifp = 0;
TRACE_INPUT(ifp, from, (char *)rip, size);
@ -76,7 +77,9 @@ rip_input(from, rip, size)
if (rip->rip_vers == 0) {
syslog(LOG_ERR,
"RIP version 0 packet received from %s! (cmd %d)",
(*afswitch[from->sa_family].af_format)(from), rip->rip_cmd);
(*afswitch[from->sa_family].af_format)(from, buf1,
sizeof(buf1)),
rip->rip_cmd);
return;
}
switch (rip->rip_cmd) {
@ -141,13 +144,31 @@ rip_input(from, rip, size)
/* verify message came from a privileged port */
if ((*afp->af_portcheck)(from) == 0)
return;
if ((ifp = if_iflookup(from)) == 0 || (ifp->int_flags &
(IFF_BROADCAST | IFF_POINTOPOINT | IFF_REMOTE)) == 0 ||
ifp->int_flags & IFF_PASSIVE) {
if ((ifp = if_iflookup(from)) == 0) {
syslog(LOG_ERR, "trace command from unknown router, %s",
(*afswitch[from->sa_family].af_format)(from));
(*afswitch[from->sa_family].af_format)(from, buf1,
sizeof(buf1)));
return;
}
if ((ifp->int_flags &
(IFF_BROADCAST|IFF_POINTOPOINT|IFF_REMOTE)) == 0) {
syslog(LOG_ERR,
"trace command from router %s, with bad flags %x",
(*afswitch[from->sa_family].af_format)(from, buf1,
sizeof(buf1)),
ifp->int_flags);
return;
}
if ((ifp->int_flags & IFF_PASSIVE) != 0) {
syslog(LOG_ERR,
"trace command from %s on an active interface",
(*afswitch[from->sa_family].af_format)(from, buf1,
sizeof(buf1)));
return;
}
((char *)rip)[size] = '\0';
if (rip->rip_cmd == RIPCMD_TRACEON)
traceon(rip->rip_tracefile);
@ -166,7 +187,8 @@ rip_input(from, rip, size)
if (ifp->int_flags & IFF_PASSIVE) {
syslog(LOG_ERR,
"bogus input (from passive interface, %s)",
(*afswitch[from->sa_family].af_format)(from));
(*afswitch[from->sa_family].af_format)(from,
buf1, sizeof(buf1)));
return;
}
rt = rtfind(from);
@ -200,7 +222,8 @@ rip_input(from, rip, size)
if (memcmp(from, &badfrom, sizeof(badfrom)) != 0) {
syslog(LOG_ERR,
"packet from unknown router, %s",
(*afswitch[from->sa_family].af_format)(from));
(*afswitch[from->sa_family].af_format)(from,
buf1, sizeof(buf1)));
badfrom = *from;
}
return;
@ -226,14 +249,18 @@ rip_input(from, rip, size)
syslog(LOG_INFO,
"route in unsupported address family (%d), from %s (af %d)\n",
n->rip_dst.sa_family,
(*afswitch[from->sa_family].af_format)(from),
(*afswitch[from->sa_family].af_format)(from,
buf1, sizeof(buf1)),
from->sa_family);
continue;
}
if (((*afp->af_checkhost)(&n->rip_dst)) == 0) {
syslog(LOG_DEBUG,
"bad host in route from %s (af %d)\n",
(*afswitch[from->sa_family].af_format)(from),
"bad host %s in route from %s (af %d)\n",
(*afswitch[n->rip_dst.sa_family].af_format)(
&n->rip_dst, buf1, sizeof(buf1)),
(*afswitch[from->sa_family].af_format)(from,
buf2, sizeof(buf2)),
from->sa_family);
continue;
}
@ -244,7 +271,8 @@ rip_input(from, rip, size)
syslog(LOG_ERR,
"bad metric (%d) from %s\n",
n->rip_metric,
(*afswitch[from->sa_family].af_format)(from));
(*afswitch[from->sa_family].af_format)(from,
buf1, sizeof(buf1)));
badfrom2 = *from;
}
continue;

View File

@ -1,4 +1,4 @@
/* $NetBSD: tables.c,v 1.12 1995/03/18 15:00:43 cgd Exp $ */
/* $NetBSD: tables.c,v 1.13 1995/05/24 15:22:57 christos Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)tables.c 8.1 (Berkeley) 6/5/93";
#else
static char rcsid[] = "$NetBSD: tables.c,v 1.12 1995/03/18 15:00:43 cgd Exp $";
static char rcsid[] = "$NetBSD: tables.c,v 1.13 1995/05/24 15:22:57 christos Exp $";
#endif
#endif /* not lint */
@ -160,6 +160,7 @@ rtadd(dst, gate, metric, state)
struct rthash *rh;
int af = dst->sa_family, flags;
u_int hash;
char buf1[256], buf2[256];
if (af >= af_max)
return;
@ -208,8 +209,10 @@ rtadd(dst, gate, metric, state)
if (errno != EEXIST && gate->sa_family < af_max)
syslog(LOG_ERR,
"adding route to net/host %s through gateway %s: %m\n",
(*afswitch[dst->sa_family].af_format)(dst),
(*afswitch[gate->sa_family].af_format)(gate));
(*afswitch[dst->sa_family].af_format)(dst, buf1,
sizeof(buf1)),
(*afswitch[gate->sa_family].af_format)(gate, buf2,
sizeof(buf2)));
perror("ADD ROUTE");
if (errno == ENETUNREACH) {
TRACE_ACTION("DELETE", rt);