summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlebel <lebel@cvs.openbsd.org>2001-06-23 15:34:03 +0000
committerlebel <lebel@cvs.openbsd.org>2001-06-23 15:34:03 +0000
commitdad031a0efc58d4f33ae94a54363676cc2bbec27 (patch)
tree8f5652351715340e5f5ee13c1aaadba3e8ce328f
parent803c2fd23dd70a9efa145ed55b59a4897dec5ea4 (diff)
use strlcpy vs strncpy+a[len-1]='\0'
-rw-r--r--usr.sbin/pppd/auth.c7
-rw-r--r--usr.sbin/pppd/chap.c7
-rw-r--r--usr.sbin/pppd/options.c22
-rw-r--r--usr.sbin/pppd/sys-bsd.c40
4 files changed, 28 insertions, 48 deletions
diff --git a/usr.sbin/pppd/auth.c b/usr.sbin/pppd/auth.c
index fb90ba01af5..90a117555e1 100644
--- a/usr.sbin/pppd/auth.c
+++ b/usr.sbin/pppd/auth.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: auth.c,v 1.18 2001/01/02 04:15:58 angelos Exp $ */
+/* $OpenBSD: auth.c,v 1.19 2001/06/23 15:34:02 lebel Exp $ */
/*
* auth.c - PPP authentication and phase control.
@@ -38,7 +38,7 @@
#if 0
static char rcsid[] = "Id: auth.c,v 1.37 1998/03/26 04:46:03 paulus Exp $";
#else
-static char rcsid[] = "$OpenBSD: auth.c,v 1.18 2001/01/02 04:15:58 angelos Exp $";
+static char rcsid[] = "$OpenBSD: auth.c,v 1.19 2001/06/23 15:34:02 lebel Exp $";
#endif
#endif
@@ -1017,8 +1017,7 @@ get_pap_passwd(passwd)
if (ret < 0)
return 0;
if (passwd != NULL) {
- strncpy(passwd, secret, MAXSECRETLEN - 1);
- passwd[MAXSECRETLEN - 1] = '\0';
+ strlcpy(passwd, secret, MAXSECRETLEN);
}
BZERO(secret, sizeof(secret));
return 1;
diff --git a/usr.sbin/pppd/chap.c b/usr.sbin/pppd/chap.c
index be2314a42ad..6648526cf3a 100644
--- a/usr.sbin/pppd/chap.c
+++ b/usr.sbin/pppd/chap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: chap.c,v 1.7 1998/01/17 20:30:19 millert Exp $ */
+/* $OpenBSD: chap.c,v 1.8 2001/06/23 15:34:02 lebel Exp $ */
/*
* chap.c - Challenge Handshake Authentication Protocol.
@@ -39,7 +39,7 @@
#if 0
static char rcsid[] = "Id: chap.c,v 1.15 1997/11/27 06:07:48 paulus Exp $";
#else
-static char rcsid[] = "$OpenBSD: chap.c,v 1.7 1998/01/17 20:30:19 millert Exp $";
+static char rcsid[] = "$OpenBSD: chap.c,v 1.8 2001/06/23 15:34:02 lebel Exp $";
#endif
#endif
@@ -431,8 +431,7 @@ ChapReceiveChallenge(cstate, inp, id, len)
/* Microsoft doesn't send their name back in the PPP packet */
if (remote_name[0] != 0 && (explicit_remote || rhostname[0] == 0)) {
- strncpy(rhostname, remote_name, sizeof(rhostname) - 1);
- rhostname[sizeof(rhostname) - 1] = 0;
+ strlcpy(rhostname, remote_name, sizeof(rhostname));
CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: using '%s' as remote name",
rhostname));
}
diff --git a/usr.sbin/pppd/options.c b/usr.sbin/pppd/options.c
index f571d0386a8..8acbd27693d 100644
--- a/usr.sbin/pppd/options.c
+++ b/usr.sbin/pppd/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.12 1998/05/08 04:52:29 millert Exp $ */
+/* $OpenBSD: options.c,v 1.13 2001/06/23 15:34:02 lebel Exp $ */
/*
* options.c - handles option processing for PPP.
@@ -23,7 +23,7 @@
#if 0
static char rcsid[] = "Id: options.c,v 1.42 1998/03/26 04:46:06 paulus Exp $";
#else
-static char rcsid[] = "$OpenBSD: options.c,v 1.12 1998/05/08 04:52:29 millert Exp $";
+static char rcsid[] = "$OpenBSD: options.c,v 1.13 2001/06/23 15:34:02 lebel Exp $";
#endif
#endif
@@ -1686,8 +1686,7 @@ setdevname(cp, quiet)
return -1;
}
- (void) strncpy(devnam, cp, MAXPATHLEN - 1);
- devnam[MAXPATHLEN - 1] = '\0';
+ (void) strlcpy(devnam, cp, MAXPATHLEN);
default_device = FALSE;
devnam_info.priv = privileged_option;
devnam_info.source = option_source;
@@ -1727,8 +1726,7 @@ setipaddr(arg)
} else {
local = *(u_int32_t *)hp->h_addr;
if (our_name[0] == 0) {
- strncpy(our_name, arg, MAXNAMELEN - 1);
- our_name[MAXNAMELEN - 1] = '\0';
+ strlcpy(our_name, arg, MAXNAMELEN);
}
}
} else
@@ -1753,8 +1751,7 @@ setipaddr(arg)
} else {
remote = *(u_int32_t *)hp->h_addr;
if (remote_name[0] == 0) {
- strncpy(remote_name, colon, MAXNAMELEN - 1);
- remote_name[MAXNAMELEN - 1] = '\0';
+ strlcpy(remote_name, colon, MAXNAMELEN);
}
}
} else
@@ -1925,8 +1922,7 @@ setname(argv)
option_error("using the name option requires root privilege");
return 0;
}
- strncpy(our_name, argv[0], MAXNAMELEN - 1);
- our_name[MAXNAMELEN - 1] = '\0';
+ strlcpy(our_name, argv[0], MAXNAMELEN);
return 1;
}
@@ -1934,8 +1930,7 @@ static int
setuser(argv)
char **argv;
{
- strncpy(user, argv[0], MAXNAMELEN - 1);
- user[MAXNAMELEN - 1] = '\0';
+ strlcpy(user, argv[0], MAXNAMELEN);
return 1;
}
@@ -1943,8 +1938,7 @@ static int
setremote(argv)
char **argv;
{
- strncpy(remote_name, argv[0], MAXNAMELEN - 1);
- remote_name[MAXNAMELEN - 1] = '\0';
+ strlcpy(remote_name, argv[0], MAXNAMELEN);
return 1;
}
diff --git a/usr.sbin/pppd/sys-bsd.c b/usr.sbin/pppd/sys-bsd.c
index 4d5aac3f7c1..84450cbfced 100644
--- a/usr.sbin/pppd/sys-bsd.c
+++ b/usr.sbin/pppd/sys-bsd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys-bsd.c,v 1.14 1998/05/08 04:52:33 millert Exp $ */
+/* $OpenBSD: sys-bsd.c,v 1.15 2001/06/23 15:34:02 lebel Exp $ */
/*
* sys-bsd.c - System-dependent procedures for setting up
@@ -26,7 +26,7 @@
#if 0
static char rcsid[] = "Id: sys-bsd.c,v 1.31 1998/04/02 12:04:19 paulus Exp $";
#else
-static char rcsid[] = "$OpenBSD: sys-bsd.c,v 1.14 1998/05/08 04:52:33 millert Exp $";
+static char rcsid[] = "$OpenBSD: sys-bsd.c,v 1.15 2001/06/23 15:34:02 lebel Exp $";
#endif
#endif
@@ -139,8 +139,7 @@ sys_cleanup()
struct ifreq ifr;
if (if_is_up) {
- strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
- ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
+ strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) >= 0
&& ((ifr.ifr_flags & IFF_UP) != 0)) {
ifr.ifr_flags &= ~IFF_UP;
@@ -190,8 +189,7 @@ ppp_available()
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
return 1; /* can't tell */
- strncpy(ifr.ifr_name, "ppp0", sizeof(ifr.ifr_name) - 1);
- ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
+ strlcpy(ifr.ifr_name, "ppp0", sizeof(ifr.ifr_name));
ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0;
close(s);
@@ -342,8 +340,7 @@ sipxfaddr(unit, network, node)
result = 0;
} else {
bzero (&ifr, sizeof(ifr));
- strncpy (ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
- ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
+ strlcpy (ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
sipx->sipx_len = sizeof(*sipx);
sipx->sipx_family = AF_IPX;
@@ -393,8 +390,7 @@ cipxfaddr(unit)
result = 0;
} else {
bzero (&ifr, sizeof(ifr));
- strncpy (ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
- ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
+ strlcpy (ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
sipx->sipx_len = sizeof(*sipx);
sipx->sipx_family = AF_IPX;
@@ -796,8 +792,7 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
u_int x;
struct ifreq ifr;
- strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
- ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
+ strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
ifr.ifr_mtu = mtu;
if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0) {
syslog(LOG_ERR, "ioctl(SIOCSIFMTU): %m");
@@ -997,8 +992,7 @@ sifup(u)
{
struct ifreq ifr;
- strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
- ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
+ strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
return 0;
@@ -1049,8 +1043,7 @@ sifdown(u)
ioctl(ppp_fd, PPPIOCSNPMODE, (caddr_t) &npi);
/* ignore errors, because ppp_fd might have been closed by now. */
- strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
- ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
+ strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
rv = 0;
@@ -1085,8 +1078,7 @@ sifaddr(u, o, h, m)
struct ifaliasreq ifra;
struct ifreq ifr;
- strncpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name) - 1);
- ifra.ifra_name[sizeof(ifra.ifra_name) - 1] = '\0';
+ strlcpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name));
SET_SA_FAMILY(ifra.ifra_addr, AF_INET);
((struct sockaddr_in *) &ifra.ifra_addr)->sin_addr.s_addr = o;
SET_SA_FAMILY(ifra.ifra_broadaddr, AF_INET);
@@ -1097,8 +1089,7 @@ sifaddr(u, o, h, m)
} else
BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask));
BZERO(&ifr, sizeof(ifr));
- strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1);
- ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
+ strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
if (ioctl(sockfd, SIOCDIFADDR, (caddr_t) &ifr) < 0) {
if (errno != EADDRNOTAVAIL)
syslog(LOG_WARNING, "Couldn't remove interface address: %m");
@@ -1129,8 +1120,7 @@ cifaddr(u, o, h)
struct ifaliasreq ifra;
ifaddrs[0] = 0;
- strncpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name) - 1);
- ifra.ifra_name[sizeof(ifra.ifra_name) - 1] = '\0';
+ strlcpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name));
SET_SA_FAMILY(ifra.ifra_addr, AF_INET);
((struct sockaddr_in *) &ifra.ifra_addr)->sin_addr.s_addr = o;
SET_SA_FAMILY(ifra.ifra_broadaddr, AF_INET);
@@ -1408,8 +1398,7 @@ get_ether_addr(ipaddr, hwaddr)
((char *)&ifr->ifr_addr + ifr->ifr_addr.sa_len)) {
if (ifr->ifr_addr.sa_family == AF_INET) {
ina = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
- strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name) - 1);
- ifreq.ifr_name[sizeof(ifreq.ifr_name) - 1] = '\0';
+ strlcpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
/*
* Check that the interface is up, and not point-to-point
* or loopback.
@@ -1509,8 +1498,7 @@ GetMask(addr)
/*
* Check that the interface is up, and not point-to-point or loopback.
*/
- strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name) - 1);
- ifreq.ifr_name[sizeof(ifreq.ifr_name) - 1] = '\0';
+ strlcpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, &ifreq) < 0)
continue;
if ((ifreq.ifr_flags & (IFF_UP|IFF_POINTOPOINT|IFF_LOOPBACK))