summaryrefslogtreecommitdiffstats
path: root/sbin/ifconfig
diff options
context:
space:
mode:
authorbrooks <brooks@FreeBSD.org>2004-01-27 01:43:14 +0000
committerbrooks <brooks@FreeBSD.org>2004-01-27 01:43:14 +0000
commit280fcfee010f264faacd1e395fd9a429bdb87843 (patch)
tree9b89f0fe994c15eaec1e34d8a459d958e8e0ead9 /sbin/ifconfig
parentdef0705074b6fa5839b347d07cc2d7f6cef85390 (diff)
downloadFreeBSD-src-280fcfee010f264faacd1e395fd9a429bdb87843.zip
FreeBSD-src-280fcfee010f264faacd1e395fd9a429bdb87843.tar.gz
Use IFNAMSIZ instead of a magic value for the length of an interface
name. Prevent the kernel from potentially overflowing the interface name variable. The size argument of strlcpy is complex because the name is not null-terminated in sdl_data.
Diffstat (limited to 'sbin/ifconfig')
-rw-r--r--sbin/ifconfig/ifconfig.c7
-rw-r--r--sbin/ifconfig/ifconfig.h2
2 files changed, 5 insertions, 4 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 0e433a5..0e6ae2b 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -113,7 +113,7 @@ struct in6_aliasreq in6_addreq =
struct sockaddr_in netmask;
struct netrange at_nr; /* AppleTalk net range */
-char name[32];
+char name[IFNAMSIZ];
int flags;
int setaddr;
int setipdst;
@@ -596,8 +596,9 @@ main(int argc, char *argv[])
addrcount++;
next += nextifm->ifm_msglen;
}
- strncpy(name, sdl->sdl_data, sdl->sdl_nlen);
- name[sdl->sdl_nlen] = '\0';
+ strlcpy(name, sdl->sdl_data,
+ sizeof(name) <= sdl->sdl_nlen ?
+ sizeof(name) : sdl->sdl_nlen + 1);
if (all || namesonly) {
if (uponly)
diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h
index 7430c69..622be54 100644
--- a/sbin/ifconfig/ifconfig.h
+++ b/sbin/ifconfig/ifconfig.h
@@ -36,7 +36,7 @@
extern struct ifreq ifr;
-extern char name[32]; /* name of interface */
+extern char name[IFNAMSIZ]; /* name of interface */
extern int allmedia;
extern int supmedia;
struct afswtch;
OpenPOWER on IntegriCloud