Gross workaround for PR 36390: don't overwrite the stack with zeroes when

using struct sockaddr_dl in an ifreq.
This commit is contained in:
tls 2007-05-27 18:11:38 +00:00
parent 8b523203e0
commit e87faddb31
2 changed files with 17 additions and 7 deletions

View File

@ -1,9 +1,11 @@
# $NetBSD: Makefile.inc,v 1.3 2006/05/11 07:17:41 mrg Exp $
# $NetBSD: Makefile.inc,v 1.4 2007/05/27 18:11:38 tls Exp $
.if exists(${.CURDIR}/../../Makefile.inc)
.include "${.CURDIR}/../../Makefile.inc"
.endif
USE_FORT?=yes # network client/server
.include <bsd.own.mk>
.if ${HAVE_GCC} == 4

View File

@ -1,4 +1,4 @@
/* $NetBSD: sys-bsd.c,v 1.55 2006/01/29 17:52:38 christos Exp $ */
/* $NetBSD: sys-bsd.c,v 1.56 2007/05/27 18:11:38 tls Exp $ */
/*
* sys-bsd.c - System-dependent procedures for setting up
@ -79,7 +79,7 @@
#if 0
#define RCSID "Id: sys-bsd.c,v 1.47 2000/04/13 12:04:23 paulus Exp "
#else
__RCSID("$NetBSD: sys-bsd.c,v 1.55 2006/01/29 17:52:38 christos Exp $");
__RCSID("$NetBSD: sys-bsd.c,v 1.56 2007/05/27 18:11:38 tls Exp $");
#endif
#endif
@ -1803,16 +1803,24 @@ get_ether_addr(u_int32_t ipaddr, struct sockaddr_dl *hwaddr)
int
get_if_hwaddr(u_char *addr, char *name)
{
struct ifreq ifreq;
struct sockaddr_dl *sdl = (struct sockaddr_dl *) &ifreq.ifr_addr;
#define IFREQ_SAFE (sizeof(struct ifreq) + sizeof(struct sockaddr_dl))
/* XXX sockaddr_dl is larger than the sockaddr in struct ifreq! */
union { /* XXX */
struct ifreq _ifreq; /* XXX */
char _X[IFREQ_SAFE]; /* XXX */
} _ifreq_dontsmashstack; /* XXX */
#define ifreq_xxx _ifreq_dontsmashstack._ifreq /* XXX */
struct sockaddr_dl *sdl = (struct sockaddr_dl *) &ifreq_xxx.ifr_addr;
int fd;
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
return 0;
(void)memset(sdl, 0, sizeof(*sdl));
sdl->sdl_family = AF_LINK;
(void)strlcpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name));
if (ioctl(fd, SIOCGIFADDR, &ifreq) == -1) {
(void)strlcpy(ifreq_xxx.ifr_name, name, sizeof(ifreq_xxx.ifr_name));
if (ioctl(fd, SIOCGIFADDR, &ifreq_xxx) == -1) {
(void)close(fd);
return 0;
}