diff options
author | Markus Friedl <markus@cvs.openbsd.org> | 2005-11-28 10:14:35 +0000 |
---|---|---|
committer | Markus Friedl <markus@cvs.openbsd.org> | 2005-11-28 10:14:35 +0000 |
commit | 0e79e526f89cf218242f8a5e6843c74ee87fe07f (patch) | |
tree | 8055d18149a7fd7e449edcace5425b82f63e7deb /sbin | |
parent | 6fdb669e6abe203d2d8d1889a77e453b860e3f4a (diff) |
do not overflow ifr.ifr_addr; ok mpf, henning, hshoexer, deraadt
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/ifconfig/ifconfig.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index ab0906c12cd..00a2432a0ab 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.c,v 1.154 2005/11/15 00:38:34 jmc Exp $ */ +/* $OpenBSD: ifconfig.c,v 1.155 2005/11/28 10:14:34 markus Exp $ */ /* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */ /* @@ -737,25 +737,23 @@ printif(char *ifname, int ifaliases) continue; } } - (void) strlcpy(name, ifa->ifa_name, sizeof(name)); - #ifdef INET6 /* quickhack: sizeof(ifr) < sizeof(ifr6) */ if (ifa->ifa_addr->sa_family == AF_INET6) { - ifrp = (struct ifreq *)&ifr6; memset(&ifr6, 0, sizeof(ifr6)); - } else { - ifrp = 𝔦 + memcpy(&ifr6.ifr_addr, ifa->ifa_addr, + MIN(sizeof(ifr6.ifr_addr), ifa->ifa_addr->sa_len)); + ifrp = (struct ifreq *)&ifr6; + } else +#endif + { memset(&ifr, 0, sizeof(ifr)); + memcpy(&ifr.ifr_addr, ifa->ifa_addr, + MIN(sizeof(ifr.ifr_addr), ifa->ifa_addr->sa_len)); + ifrp = 𝔦 } -#else /* INET6 */ - ifrp = 𝔦 - memset(&ifr, 0, sizeof(ifr)); -#endif /* INET6 */ - + strlcpy(name, ifa->ifa_name, sizeof(name)); strlcpy(ifrp->ifr_name, ifa->ifa_name, sizeof(ifrp->ifr_name)); - /* XXX boundary check? */ - memcpy(&ifrp->ifr_addr, ifa->ifa_addr, ifa->ifa_addr->sa_len); if (ifa->ifa_addr->sa_family == AF_LINK) { namep = ifa->ifa_name; |