Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/ifconfig fix alignment problem of SIOCGIFCONF, on 64bit...
details: https://anonhg.NetBSD.org/src/rev/abf7bf20af53
branches: trunk
changeset: 475016:abf7bf20af53
user: itojun <itojun%NetBSD.org@localhost>
date: Thu Jul 29 15:40:48 1999 +0000
description:
fix alignment problem of SIOCGIFCONF, on 64bit arch.
diffstat:
sbin/ifconfig/ifconfig.c | 37 +++++++++++++++++++++++++++++--------
1 files changed, 29 insertions(+), 8 deletions(-)
diffs (102 lines):
diff -r aa3c403c4e7c -r abf7bf20af53 sbin/ifconfig/ifconfig.c
--- a/sbin/ifconfig/ifconfig.c Thu Jul 29 14:20:32 1999 +0000
+++ b/sbin/ifconfig/ifconfig.c Thu Jul 29 15:40:48 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ifconfig.c,v 1.57 1999/07/26 19:38:36 thorpej Exp $ */
+/* $NetBSD: ifconfig.c,v 1.58 1999/07/29 15:40:48 itojun Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -80,7 +80,7 @@
#if 0
static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
#else
-__RCSID("$NetBSD: ifconfig.c,v 1.57 1999/07/26 19:38:36 thorpej Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.58 1999/07/29 15:40:48 itojun Exp $");
#endif
#endif /* not lint */
@@ -614,7 +614,8 @@
char inbuf[8192];
struct ifconf ifc;
struct ifreq *ifr;
- int i;
+ int i, siz;
+ char ifrbuf[8192];
ifc.ifc_len = sizeof(inbuf);
ifc.ifc_buf = inbuf;
@@ -626,10 +627,16 @@
ifr = ifc.ifc_req;
for (i = 0; i < ifc.ifc_len; ) {
ifr = (struct ifreq *)((caddr_t)ifc.ifc_req + i);
- i += sizeof(ifr->ifr_name) +
+ siz = sizeof(ifr->ifr_name) +
(ifr->ifr_addr.sa_len > sizeof(struct sockaddr)
? ifr->ifr_addr.sa_len
: sizeof(struct sockaddr));
+ i += siz;
+ /* avoid alignment issue */
+ if (sizeof(ifrbuf) < siz)
+ errx(1, "ifr too big");
+ memcpy(ifrbuf, ifr, siz);
+ ifr = (struct ifreq *)ifrbuf;
if (!strncmp(iname, ifr->ifr_name, sizeof(ifr->ifr_name))) {
if (ifr->ifr_addr.sa_family == af)
switch (af) {
@@ -651,7 +658,8 @@
const struct sockaddr_dl *sdl = NULL;
struct ifconf ifc;
struct ifreq ifreq, *ifr;
- int i, idx;
+ int i, siz, idx;
+ char ifrbuf[8192];
ifc.ifc_len = sizeof(inbuf);
ifc.ifc_buf = inbuf;
@@ -664,10 +672,16 @@
ifreq.ifr_name[0] = '\0';
for (i = 0, idx = 0; i < ifc.ifc_len; ) {
ifr = (struct ifreq *)((caddr_t)ifc.ifc_req + i);
- i += sizeof(ifr->ifr_name) +
+ siz = sizeof(ifr->ifr_name) +
(ifr->ifr_addr.sa_len > sizeof(struct sockaddr)
? ifr->ifr_addr.sa_len
: sizeof(struct sockaddr));
+ i += siz;
+ /* avoid alignment issue */
+ if (sizeof(ifrbuf) < siz)
+ errx(1, "ifr too big");
+ memcpy(ifrbuf, ifr, siz);
+ ifr = (struct ifreq *)ifrbuf;
if (ifr->ifr_addr.sa_family == AF_LINK)
sdl = (const struct sockaddr_dl *) &ifr->ifr_addr;
if (!strncmp(ifreq.ifr_name, ifr->ifr_name,
@@ -1566,7 +1580,8 @@
char inbuf[8192];
struct ifconf ifc;
struct ifreq *ifr;
- int i;
+ int i, siz;
+ char ifrbuf[8192];
ifc.ifc_len = sizeof(inbuf);
ifc.ifc_buf = inbuf;
@@ -1578,10 +1593,16 @@
ifr = ifc.ifc_req;
for (i = 0; i < ifc.ifc_len; ) {
ifr = (struct ifreq *)((caddr_t)ifc.ifc_req + i);
- i += sizeof(ifr->ifr_name) +
+ siz = sizeof(ifr->ifr_name) +
(ifr->ifr_addr.sa_len > sizeof(struct sockaddr)
? ifr->ifr_addr.sa_len
: sizeof(struct sockaddr));
+ i += siz;
+ /* avoid alignment issue */
+ if (sizeof(ifrbuf) < siz)
+ errx(1, "ifr too big");
+ memcpy(ifrbuf, ifr, siz);
+ ifr = (struct ifreq *)ifrbuf;
if (!strncmp(name, ifr->ifr_name, sizeof(ifr->ifr_name))) {
if (ifr->ifr_addr.sa_family == AF_INET6)
in6_alias((struct in6_ifreq *)ifr);
Home |
Main Index |
Thread Index |
Old Index