fix incorrect usage of strncpy() to (an internal implementation of)

estrlcpy().

okay christos
This commit is contained in:
elad 2006-06-16 23:48:35 +00:00
parent 6d05bd66ec
commit d10cf99230
9 changed files with 78 additions and 68 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: af_atalk.c,v 1.2 2006/06/14 11:05:42 tron Exp $ */
/* $NetBSD: af_atalk.c,v 1.3 2006/06/16 23:48:35 elad Exp $ */
/*
* Copyright (c) 1983, 1993
@ -33,7 +33,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: af_atalk.c,v 1.2 2006/06/14 11:05:42 tron Exp $");
__RCSID("$NetBSD: af_atalk.c,v 1.3 2006/06/16 23:48:35 elad Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -131,7 +131,7 @@ at_status(int force)
err(EXIT_FAILURE, "socket");
}
(void) memset(&ifr, 0, sizeof(ifr));
(void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
estrlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(s, SIOCGIFADDR, &ifr) == -1) {
if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
if (!force)
@ -140,7 +140,7 @@ at_status(int force)
} else
warn("SIOCGIFADDR");
}
(void) strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
estrlcpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
sat = (struct sockaddr_at *)&ifr.ifr_addr;
(void) memset(&null_sat, 0, sizeof(null_sat));
@ -157,7 +157,7 @@ at_status(int force)
else
warn("SIOCGIFDSTADDR");
}
(void) strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
estrlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
sat = (struct sockaddr_at *)&ifr.ifr_dstaddr;
if (!sat)
sat = &null_sat;

View File

@ -1,4 +1,4 @@
/* $NetBSD: af_inet.c,v 1.2 2006/06/14 11:05:42 tron Exp $ */
/* $NetBSD: af_inet.c,v 1.3 2006/06/16 23:48:35 elad Exp $ */
/*
* Copyright (c) 1983, 1993
@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: af_inet.c,v 1.2 2006/06/14 11:05:42 tron Exp $");
__RCSID("$NetBSD: af_inet.c,v 1.3 2006/06/16 23:48:35 elad Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -88,7 +88,7 @@ in_alias(struct ifreq *creq)
err(EXIT_FAILURE, "socket");
}
(void) memset(&ifr, 0, sizeof(ifr));
(void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
estrlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(s, SIOCGIFADDR, &ifr) == -1) {
if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
return;
@ -100,7 +100,7 @@ in_alias(struct ifreq *creq)
sizeof(creq->ifr_addr)) == 0)
alias = 0;
(void) memset(&in_addreq, 0, sizeof(in_addreq));
(void) strncpy(in_addreq.ifra_name, name, sizeof(in_addreq.ifra_name));
estrlcpy(in_addreq.ifra_name, name, sizeof(in_addreq.ifra_name));
memcpy(&in_addreq.ifra_addr, &creq->ifr_addr,
sizeof(in_addreq.ifra_addr));
if (ioctl(s, SIOCGIFALIAS, &in_addreq) == -1) {
@ -145,7 +145,7 @@ in_status(int force)
continue;
memset(&isifr, 0, sizeof(isifr));
strncpy(isifr.ifr_name, ifa->ifa_name, sizeof(isifr.ifr_name));
estrlcpy(isifr.ifr_name, ifa->ifa_name, sizeof(isifr.ifr_name));
memcpy(&isifr.ifr_addr, ifa->ifa_addr, ifa->ifa_addr->sa_len);
in_alias(&isifr);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: af_inet6.c,v 1.3 2006/06/14 11:05:42 tron Exp $ */
/* $NetBSD: af_inet6.c,v 1.4 2006/06/16 23:48:35 elad Exp $ */
/*
* Copyright (c) 1983, 1993
@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: af_inet6.c,v 1.3 2006/06/14 11:05:42 tron Exp $");
__RCSID("$NetBSD: af_inet6.c,v 1.4 2006/06/16 23:48:35 elad Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -246,7 +246,7 @@ in6_alias(struct in6_ifreq *creq)
if (flags & IFF_POINTOPOINT) {
(void) memset(&ifr6, 0, sizeof(ifr6));
(void) strncpy(ifr6.ifr_name, name, sizeof(ifr6.ifr_name));
estrlcpy(ifr6.ifr_name, name, sizeof(ifr6.ifr_name));
ifr6.ifr_addr = creq->ifr_addr;
if (ioctl(s, SIOCGIFDSTADDR_IN6, &ifr6) == -1) {
if (errno != EADDRNOTAVAIL)
@ -265,7 +265,7 @@ in6_alias(struct in6_ifreq *creq)
}
(void) memset(&ifr6, 0, sizeof(ifr6));
(void) strncpy(ifr6.ifr_name, name, sizeof(ifr6.ifr_name));
estrlcpy(ifr6.ifr_name, name, sizeof(ifr6.ifr_name));
ifr6.ifr_addr = creq->ifr_addr;
if (ioctl(s, SIOCGIFNETMASK_IN6, &ifr6) == -1) {
if (errno != EADDRNOTAVAIL)
@ -277,7 +277,7 @@ in6_alias(struct in6_ifreq *creq)
}
(void) memset(&ifr6, 0, sizeof(ifr6));
(void) strncpy(ifr6.ifr_name, name, sizeof(ifr6.ifr_name));
estrlcpy(ifr6.ifr_name, name, sizeof(ifr6.ifr_name));
ifr6.ifr_addr = creq->ifr_addr;
if (ioctl(s, SIOCGIFAFLAG_IN6, &ifr6) == -1) {
if (errno != EADDRNOTAVAIL)
@ -301,7 +301,7 @@ in6_alias(struct in6_ifreq *creq)
if (Lflag) {
struct in6_addrlifetime *lifetime;
(void) memset(&ifr6, 0, sizeof(ifr6));
(void) strncpy(ifr6.ifr_name, name, sizeof(ifr6.ifr_name));
estrlcpy(ifr6.ifr_name, name, sizeof(ifr6.ifr_name));
ifr6.ifr_addr = creq->ifr_addr;
lifetime = &ifr6.ifr_ifru.ifru_lifetime;
if (ioctl(s, SIOCGIFALIFETIME_IN6, &ifr6) == -1) {
@ -347,7 +347,7 @@ in6_status(int force)
continue;
memset(&isifr, 0, sizeof(isifr));
strncpy(isifr.ifr_name, ifa->ifa_name, sizeof(isifr.ifr_name));
estrlcpy(isifr.ifr_name, ifa->ifa_name, sizeof(isifr.ifr_name));
memcpy(&isifr.ifr_addr, ifa->ifa_addr, ifa->ifa_addr->sa_len);
in6_alias(&isifr);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: af_iso.c,v 1.2 2006/06/14 11:05:42 tron Exp $ */
/* $NetBSD: af_iso.c,v 1.3 2006/06/16 23:48:35 elad Exp $ */
/*
* Copyright (c) 1983, 1993
@ -33,7 +33,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: af_iso.c,v 1.2 2006/06/14 11:05:42 tron Exp $");
__RCSID("$NetBSD: af_iso.c,v 1.3 2006/06/16 23:48:35 elad Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -128,7 +128,7 @@ iso_status(int force)
err(EXIT_FAILURE, "socket");
}
(void) memset(&isoifr, 0, sizeof(isoifr));
(void) strncpy(isoifr.ifr_name, name, sizeof(isoifr.ifr_name));
estrlcpy(isoifr.ifr_name, name, sizeof(isoifr.ifr_name));
if (ioctl(s, SIOCGIFADDR_ISO, &isoifr) == -1) {
if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
if (!force)
@ -138,7 +138,7 @@ iso_status(int force)
} else
warn("SIOCGIFADDR_ISO");
}
(void) strncpy(isoifr.ifr_name, name, sizeof isoifr.ifr_name);
strlcpy(isoifr.ifr_name, name, sizeof isoifr.ifr_name);
siso = &isoifr.ifr_Addr;
printf("\tiso %s ", iso_ntoa(&siso->siso_addr));
if (ioctl(s, SIOCGIFNETMASK_ISO, &isoifr) == -1) {
@ -160,7 +160,7 @@ iso_status(int force)
else
warn("SIOCGIFDSTADDR_ISO");
}
(void) strncpy(isoifr.ifr_name, name, sizeof (isoifr.ifr_name));
strlcpy(isoifr.ifr_name, name, sizeof (isoifr.ifr_name));
siso = &isoifr.ifr_Addr;
printf("--> %s ", iso_ntoa(&siso->siso_addr));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: af_ns.c,v 1.3 2006/06/14 11:05:42 tron Exp $ */
/* $NetBSD: af_ns.c,v 1.4 2006/06/16 23:48:35 elad Exp $ */
/*
* Copyright (c) 1983, 1993
@ -33,7 +33,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: af_ns.c,v 1.3 2006/06/14 11:05:42 tron Exp $");
__RCSID("$NetBSD: af_ns.c,v 1.4 2006/06/16 23:48:35 elad Exp $");
#endif /* not lint */
/*
@ -104,7 +104,7 @@ xns_status(int force)
err(EXIT_FAILURE, "socket");
}
(void) memset(&ifr, 0, sizeof(ifr));
(void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
estrlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(s, SIOCGIFADDR, &ifr) == -1) {
if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
if (!force)
@ -113,7 +113,7 @@ xns_status(int force)
} else
warn("SIOCGIFADDR");
}
(void) strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
estrlcpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
sns = (struct sockaddr_ns *)&ifr.ifr_addr;
printf("\tns %s ", ns_ntoa(sns->sns_addr));
if (flags & IFF_POINTOPOINT) { /* by W. Nesheim@Cornell */
@ -123,7 +123,7 @@ xns_status(int force)
else
warn("SIOCGIFDSTADDR");
}
(void) strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
estrlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
sns = (struct sockaddr_ns *)&ifr.ifr_dstaddr;
printf("--> %s ", ns_ntoa(sns->sns_addr));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.8 2005/03/20 02:43:50 thorpej Exp $ */
/* $NetBSD: extern.h,v 1.9 2006/06/16 23:48:35 elad Exp $ */
/*
* Copyright (c) 1983, 1993
@ -70,3 +70,4 @@ const struct afswtch *lookup_af_bynum(int);
const char *get_string(const char *, const char *, u_int8_t *, int *);
void print_string(const u_int8_t *, int);
void getsock(int);
void estrlcpy(char *, char *, size_t);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ieee80211.c,v 1.5 2006/04/29 21:32:29 rpaulo Exp $ */
/* $NetBSD: ieee80211.c,v 1.6 2006/06/16 23:48:35 elad Exp $ */
/*
* Copyright (c) 1983, 1993
@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: ieee80211.c,v 1.5 2006/04/29 21:32:29 rpaulo Exp $");
__RCSID("$NetBSD: ieee80211.c,v 1.6 2006/06/16 23:48:35 elad Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -62,7 +62,7 @@ set80211(int type, int val, int len, u_int8_t *data)
struct ieee80211req ireq;
(void) memset(&ireq, 0, sizeof(ireq));
(void) strncpy(ireq.i_name, name, sizeof(ireq.i_name));
estrlcpy(ireq.i_name, name, sizeof(ireq.i_name));
ireq.i_type = type;
ireq.i_val = val;
ireq.i_len = len;
@ -89,7 +89,7 @@ get80211opmode(void)
struct ifmediareq ifmr;
(void) memset(&ifmr, 0, sizeof(ifmr));
(void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
estrlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) {
if (ifmr.ifm_current & IFM_IEEE80211_ADHOC)
return IEEE80211_M_IBSS; /* XXX ahdemo */
@ -112,7 +112,7 @@ setifnwid(const char *val, int d)
if (get_string(val, NULL, nwid.i_nwid, &len) == NULL)
return;
nwid.i_len = len;
(void)strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
estrlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_data = (void *)&nwid;
if (ioctl(s, SIOCS80211NWID, &ifr) == -1)
warn("SIOCS80211NWID");
@ -136,7 +136,7 @@ setifbssid(const char *val, int d)
memcpy(&bssid.i_bssid, ea->ether_addr_octet,
sizeof(bssid.i_bssid));
}
(void)strncpy(bssid.i_name, name, sizeof(bssid.i_name));
estrlcpy(bssid.i_name, name, sizeof(bssid.i_name));
if (ioctl(s, SIOCS80211BSSID, &bssid) == -1)
warn("SIOCS80211BSSID");
}
@ -157,7 +157,7 @@ setifchan(const char *val, int d)
}
}
(void)strncpy(channel.i_name, name, sizeof(channel.i_name));
estrlcpy(channel.i_name, name, sizeof(channel.i_name));
channel.i_channel = (u_int16_t) chan;
if (ioctl(s, SIOCS80211CHANNEL, &channel) == -1)
warn("SIOCS80211CHANNEL");
@ -217,7 +217,7 @@ setifnwkey(const char *val, int d)
}
for (; i < IEEE80211_WEP_NKID; i++)
nwkey.i_key[i].i_keylen = 0;
(void)strncpy(nwkey.i_name, name, sizeof(nwkey.i_name));
estrlcpy(nwkey.i_name, name, sizeof(nwkey.i_name));
if (ioctl(s, SIOCS80211NWKEY, &nwkey) == -1)
warn("SIOCS80211NWKEY");
}
@ -227,7 +227,7 @@ setifpowersave(const char *val, int d)
{
struct ieee80211_power power;
(void)strncpy(power.i_name, name, sizeof(power.i_name));
estrlcpy(power.i_name, name, sizeof(power.i_name));
if (ioctl(s, SIOCG80211POWER, &power) == -1) {
warn("SIOCG80211POWER");
return;
@ -243,7 +243,7 @@ setifpowersavesleep(const char *val, int d)
{
struct ieee80211_power power;
(void)strncpy(power.i_name, name, sizeof(power.i_name));
estrlcpy(power.i_name, name, sizeof(power.i_name));
if (ioctl(s, SIOCG80211POWER, &power) == -1) {
warn("SIOCG80211POWER");
return;
@ -262,7 +262,7 @@ ieee80211_statistics(void)
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_buflen = sizeof(stats);
ifr.ifr_buf = (caddr_t)&stats;
(void)strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
estrlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(s, (zflag) ? SIOCG80211ZSTATS : SIOCG80211STATS,
(caddr_t)&ifr) == -1)
return;
@ -371,7 +371,7 @@ ieee80211_status(void)
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_data = (void *)&nwid;
(void)strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
estrlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(s, SIOCG80211NWID, &ifr) == -1)
return;
if (nwid.i_len > IEEE80211_NWID_LEN) {
@ -382,7 +382,7 @@ ieee80211_status(void)
print_string(nwid.i_nwid, nwid.i_len);
if (opmode == IEEE80211_M_HOSTAP) {
(void)strncpy(ireq.i_name, name, sizeof(ireq.i_name));
estrlcpy(ireq.i_name, name, sizeof(ireq.i_name));
ireq.i_type = IEEE80211_IOC_HIDESSID;
if (ioctl(s, SIOCG80211, &ireq) != -1) {
if (ireq.i_val)
@ -401,7 +401,7 @@ ieee80211_status(void)
}
memset(&nwkey, 0, sizeof(nwkey));
(void)strncpy(nwkey.i_name, name, sizeof(nwkey.i_name));
estrlcpy(nwkey.i_name, name, sizeof(nwkey.i_name));
/* show nwkey only when WEP is enabled */
if (ioctl(s, SIOCG80211NWKEY, &nwkey) == -1 ||
nwkey.i_wepon == 0) {
@ -458,7 +458,7 @@ ieee80211_status(void)
printf("\n");
skip_wep:
(void)strncpy(power.i_name, name, sizeof(power.i_name));
estrlcpy(power.i_name, name, sizeof(power.i_name));
if (ioctl(s, SIOCG80211POWER, &power) == -1)
goto skip_power;
printf("\tpowersave ");
@ -469,10 +469,10 @@ ieee80211_status(void)
printf("\n");
skip_power:
(void)strncpy(bssid.i_name, name, sizeof(bssid.i_name));
estrlcpy(bssid.i_name, name, sizeof(bssid.i_name));
if (ioctl(s, SIOCG80211BSSID, &bssid) == -1)
return;
(void)strncpy(channel.i_name, name, sizeof(channel.i_name));
estrlcpy(channel.i_name, name, sizeof(channel.i_name));
if (ioctl(s, SIOCG80211CHANNEL, &channel) == -1)
return;
if (memcmp(bssid.i_bssid, zero_macaddr, IEEE80211_ADDR_LEN) == 0) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: ifconfig.c,v 1.171 2006/05/18 09:05:50 liamjfoy Exp $ */
/* $NetBSD: ifconfig.c,v 1.172 2006/06/16 23:48:35 elad Exp $ */
/*-
* Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
@ -76,7 +76,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
#if 0
static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
#else
__RCSID("$NetBSD: ifconfig.c,v 1.171 2006/05/18 09:05:50 liamjfoy Exp $");
__RCSID("$NetBSD: ifconfig.c,v 1.172 2006/06/16 23:48:35 elad Exp $");
#endif
#endif /* not lint */
@ -518,7 +518,7 @@ main(int argc, char *argv[])
af = afp->af_af;
/* Get information about the interface. */
(void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
estrlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (getinfo(&ifr) < 0)
exit(1);
@ -615,18 +615,18 @@ main(int argc, char *argv[])
#endif /* INET_ONLY */
if (clearaddr) {
(void) strncpy(afp->af_ridreq, name, sizeof ifr.ifr_name);
estrlcpy(afp->af_ridreq, name, sizeof ifr.ifr_name);
if (ioctl(s, afp->af_difaddr, afp->af_ridreq) == -1)
err(EXIT_FAILURE, "SIOCDIFADDR");
}
if (newaddr > 0) {
(void) strncpy(afp->af_addreq, name, sizeof ifr.ifr_name);
estrlcpy(afp->af_addreq, name, sizeof ifr.ifr_name);
if (ioctl(s, afp->af_aifaddr, afp->af_addreq) == -1)
warn("SIOCAIFADDR");
}
if (g_ifcr_updated) {
(void) strncpy(g_ifcr.ifcr_name, name,
strlcpy(g_ifcr.ifcr_name, name,
sizeof(g_ifcr.ifcr_name));
if (ioctl(s, SIOCSIFCAP, &g_ifcr) == -1)
err(EXIT_FAILURE, "SIOCSIFCAP");
@ -696,7 +696,7 @@ getinfo(struct ifreq *giifr)
mtu = giifr->ifr_mtu;
memset(&g_ifcr, 0, sizeof(g_ifcr));
strcpy(g_ifcr.ifcr_name, giifr->ifr_name);
estrlcpy(g_ifcr.ifcr_name, giifr->ifr_name, sizeof(g_ifcr.ifcr_name));
(void) ioctl(s, SIOCGIFCAP, &g_ifcr);
return (0);
@ -717,7 +717,7 @@ printall(const char *ifname)
idx = 0;
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
memset(&paifr, 0, sizeof(paifr));
strncpy(paifr.ifr_name, ifa->ifa_name, sizeof(paifr.ifr_name));
estrlcpy(paifr.ifr_name, ifa->ifa_name, sizeof(paifr.ifr_name));
if (sizeof(paifr.ifr_addr) >= ifa->ifa_addr->sa_len) {
memcpy(&paifr.ifr_addr, ifa->ifa_addr,
ifa->ifa_addr->sa_len);
@ -812,7 +812,7 @@ clone_create(const char *addr, int param)
/* We're called early... */
getsock(AF_INET);
(void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
estrlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(s, SIOCIFCREATE, &ifr) == -1)
err(EXIT_FAILURE, "SIOCIFCREATE");
}
@ -822,7 +822,7 @@ void
clone_destroy(const char *addr, int param)
{
(void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
estrlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
if (ioctl(s, SIOCIFDESTROY, &ifr) == -1)
err(EXIT_FAILURE, "SIOCIFDESTROY");
}
@ -843,7 +843,7 @@ setifaddr(const char *addr, int param)
newaddr = 1;
if (doalias == 0 && afp->af_gifaddr != 0) {
siifr = (struct ifreq *)afp->af_ridreq;
(void) strncpy(siifr->ifr_name, name, sizeof(siifr->ifr_name));
estrlcpy(siifr->ifr_name, name, sizeof(siifr->ifr_name));
siifr->ifr_addr.sa_family = afp->af_af;
if (ioctl(s, afp->af_gifaddr, afp->af_ridreq) == 0)
clearaddr = 1;
@ -907,7 +907,7 @@ setifflags(const char *vname, int value)
{
struct ifreq ifreq;
(void) strncpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name));
estrlcpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name));
if (ioctl(s, SIOCGIFFLAGS, &ifreq) == -1)
err(EXIT_FAILURE, "SIOCGIFFLAGS");
flags = ifreq.ifr_flags;
@ -940,7 +940,7 @@ setifmetric(const char *val, int d)
{
char *ep = NULL;
(void) strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
estrlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
ifr.ifr_metric = strtoul(val, &ep, 10);
if (!ep || *ep)
errx(EXIT_FAILURE, "%s: invalid metric", val);
@ -953,7 +953,7 @@ setifmtu(const char *val, int d)
{
char *ep = NULL;
(void)strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
estrlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_mtu = strtoul(val, &ep, 10);
if (!ep || *ep)
errx(EXIT_FAILURE, "%s: invalid mtu", val);
@ -1056,7 +1056,7 @@ init_current_media(void)
*/
if ((actions & (A_MEDIA|A_MEDIAOPT|A_MEDIAMODE)) == 0) {
(void) memset(&ifmr, 0, sizeof(ifmr));
(void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
estrlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
if (ioctl(s, SIOCGIFMEDIA, &ifmr) == -1) {
/*
@ -1091,7 +1091,7 @@ process_media_commands(void)
media_current |= mediaopt_set;
media_current &= ~mediaopt_clear;
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
estrlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
ifr.ifr_media = media_current;
if (ioctl(s, SIOCSIFMEDIA, &ifr) == -1)
@ -1270,7 +1270,7 @@ carrier(void)
struct ifmediareq ifmr;
(void) memset(&ifmr, 0, sizeof(ifmr));
(void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
estrlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
if (ioctl(s, SIOCGIFMEDIA, &ifmr) == -1) {
/*
@ -1342,7 +1342,7 @@ status(const struct sockaddr_dl *sdl)
printf("\taddress: %s\n", hbuf);
(void) memset(&ifmr, 0, sizeof(ifmr));
(void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
estrlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
if (ioctl(s, SIOCGIFMEDIA, &ifmr) == -1) {
/*
@ -1429,7 +1429,7 @@ status(const struct sockaddr_dl *sdl)
if (!vflag && !zflag)
goto proto_status;
(void) strncpy(ifdr.ifdr_name, name, sizeof(ifdr.ifdr_name));
estrlcpy(ifdr.ifdr_name, name, sizeof(ifdr.ifdr_name));
if (ioctl(s, zflag ? SIOCZIFDATA:SIOCGIFDATA, &ifdr) == -1) {
err(EXIT_FAILURE, zflag ? "SIOCZIFDATA" : "SIOCGIFDATA");
@ -1550,3 +1550,12 @@ usage(void)
progname, progname, progname, progname, progname, progname);
exit(1);
}
void
estrlcpy(char *dst, char *src, size_t len)
{
if (strlcpy(dst, src, len) >= len) {
errno = ENAMETOOLONG;
err(1, "Cannot copy `%s'", src);
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: tunnel.c,v 1.5 2005/03/20 01:09:16 thorpej Exp $ */
/* $NetBSD: tunnel.c,v 1.6 2006/06/16 23:48:35 elad Exp $ */
/*
* Copyright (c) 1983, 1993
@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: tunnel.c,v 1.5 2005/03/20 01:09:16 thorpej Exp $");
__RCSID("$NetBSD: tunnel.c,v 1.6 2006/06/16 23:48:35 elad Exp $");
#endif /* not lint */
#include <sys/param.h>
@ -86,7 +86,7 @@ settunnel(const char *src, const char *dst)
errx(EXIT_FAILURE, "invalid sockaddr");
memset(&req, 0, sizeof(req));
strncpy(req.iflr_name, name, sizeof(req.iflr_name));
estrlcpy(req.iflr_name, name, sizeof(req.iflr_name));
memcpy(&req.addr, srcres->ai_addr, srcres->ai_addrlen);
memcpy(&req.dstaddr, dstres->ai_addr, dstres->ai_addrlen);
@ -146,7 +146,7 @@ tunnel_status(void)
psrcaddr[0] = pdstaddr[0] = '\0';
memset(&req, 0, sizeof(req));
strncpy(req.iflr_name, name, IFNAMSIZ);
estrlcpy(req.iflr_name, name, IFNAMSIZ);
if (ioctl(s, SIOCGLIFPHYADDR, &req) == -1)
return;
lafp = lookup_af_bynum(req.addr.ss_family);