mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 12:54:27 +00:00
use strlcpy() and snprintf().
Obtained from: KAME MFC after: 1 week
This commit is contained in:
parent
c0efcff271
commit
bb58b617fb
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=118786
|
@ -1,5 +1,5 @@
|
|||
/* $FreeBSD$ */
|
||||
/* $KAME: advcap.c,v 1.5 2001/02/01 09:12:08 jinmei Exp $ */
|
||||
/* $KAME: advcap.c,v 1.11 2003/05/19 09:46:50 keiichi Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983 The Regents of the University of California.
|
||||
|
@ -206,7 +206,7 @@ tnchktc()
|
|||
/* p now points to beginning of last field */
|
||||
if (p[0] != 't' || p[1] != 'c')
|
||||
return (1);
|
||||
strcpy(tcname, p+3);
|
||||
strlcpy(tcname, p + 3, sizeof tcname);
|
||||
q = tcname;
|
||||
while (*q && *q != ':')
|
||||
q++;
|
||||
|
|
|
@ -602,7 +602,7 @@ makeentry(buf, len, id, string, add)
|
|||
{
|
||||
char *ep = buf + len;
|
||||
|
||||
strcpy(buf, string);
|
||||
strlcpy(buf, string, len);
|
||||
if (add) {
|
||||
char *cp;
|
||||
|
||||
|
|
|
@ -83,17 +83,17 @@ static char *
|
|||
ether_str(sdl)
|
||||
struct sockaddr_dl *sdl;
|
||||
{
|
||||
static char ebuf[32];
|
||||
static char hbuf[32];
|
||||
u_char *cp;
|
||||
|
||||
if (sdl->sdl_alen && sdl->sdl_alen > 5) {
|
||||
cp = (u_char *)LLADDR(sdl);
|
||||
sprintf(ebuf, "%x:%x:%x:%x:%x:%x",
|
||||
snprintf(hbuf, sizeof(hbuf), "%x:%x:%x:%x:%x:%x",
|
||||
cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]);
|
||||
} else
|
||||
sprintf(ebuf, "NONE");
|
||||
snprintf(hbuf, sizeof(hbuf), "NONE");
|
||||
|
||||
return(ebuf);
|
||||
return(hbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $KAME: dump.c,v 1.8 2000/10/05 22:20:39 itojun Exp $ */
|
||||
/* $KAME: dump.c,v 1.12 2003/04/11 10:14:55 jinmei Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999 WIDE Project.
|
||||
|
@ -117,6 +117,8 @@ sec2str(total)
|
|||
int days, hours, mins, secs;
|
||||
int first = 1;
|
||||
char *p = result;
|
||||
char *ep = &result[sizeof(result)];
|
||||
int n;
|
||||
|
||||
days = total / 3600 / 24;
|
||||
hours = (total / 3600) % 24;
|
||||
|
@ -125,16 +127,25 @@ sec2str(total)
|
|||
|
||||
if (days) {
|
||||
first = 0;
|
||||
p += sprintf(p, "%dd", days);
|
||||
n = snprintf(p, ep - p, "%dd", days);
|
||||
if (n < 0 || n >= ep - p)
|
||||
return "?";
|
||||
p += n;
|
||||
}
|
||||
if (!first || hours) {
|
||||
first = 0;
|
||||
p += sprintf(p, "%dh", hours);
|
||||
n = snprintf(p, ep - p, "%dh", hours);
|
||||
if (n < 0 || n >= ep - p)
|
||||
return "?";
|
||||
p += n;
|
||||
}
|
||||
if (!first || mins) {
|
||||
first = 0;
|
||||
p += sprintf(p, "%dm", mins);
|
||||
n = snprintf(p, ep - p, "%dm", mins);
|
||||
if (n < 0 || n >= ep - p)
|
||||
return "?";
|
||||
p += n;
|
||||
}
|
||||
sprintf(p, "%ds", secs);
|
||||
snprintf(p, ep - p, "%ds", secs);
|
||||
return(result);
|
||||
}
|
||||
|
|
|
@ -110,8 +110,8 @@ defrouter_probe(int ifindex)
|
|||
warnmsg(LOG_ERR, __func__, "socket: %s", strerror(errno));
|
||||
return;
|
||||
}
|
||||
bzero(&dr, sizeof(dr));
|
||||
strcpy(dr.ifname, "lo0"); /* dummy interface */
|
||||
memset(&dr, 0, sizeof(dr));
|
||||
strlcpy(dr.ifname, "lo0", sizeof dr.ifname); /* dummy interface */
|
||||
if (ioctl(s, SIOCGDRLST_IN6, (caddr_t)&dr) < 0) {
|
||||
warnmsg(LOG_ERR, __func__, "ioctl(SIOCGDRLST_IN6): %s",
|
||||
strerror(errno));
|
||||
|
@ -148,7 +148,7 @@ sendprobe(struct in6_addr *addr, int ifindex)
|
|||
u_char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
|
||||
int hoplimit = 1;
|
||||
|
||||
bzero(&sa6_probe, sizeof(sa6_probe));
|
||||
memset(&sa6_probe, 0, sizeof(sa6_probe));
|
||||
sa6_probe.sin6_family = AF_INET6;
|
||||
sa6_probe.sin6_len = sizeof(sa6_probe);
|
||||
sa6_probe.sin6_addr = *addr;
|
||||
|
|
|
@ -359,7 +359,7 @@ ifconfig(char *ifname)
|
|||
memset(ifinfo, 0, sizeof(*ifinfo));
|
||||
ifinfo->sdl = sdl;
|
||||
|
||||
strncpy(ifinfo->ifname, ifname, sizeof(ifinfo->ifname));
|
||||
strlcpy(ifinfo->ifname, ifname, sizeof(ifinfo->ifname));
|
||||
|
||||
/* construct a router solicitation message */
|
||||
if (make_packet(ifinfo))
|
||||
|
|
Loading…
Reference in a new issue