Module Name: src
Committed By: joerg
Date: Fri Nov 13 23:11:08 UTC 2009
Modified Files:
src/sys/net: if.c
Log Message:
Simplify ifreq_setaddr:
- Drop the INET6 block. The commands are never given to this function
and truncating the sockaddr is arguably not the desired result anyway.
- Clear the address before copying. This fixes SIOCGIFNETMASK and possible
other ioctls for users that don't check sa_len. This includes
COMPAT_43 and Linux emulation.
OK dyoung@
To generate a diff of this commit:
cvs rdiff -u -r1.240 -r1.241 src/sys/net/if.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.240 src/sys/net/if.c:1.241
--- src/sys/net/if.c:1.240 Mon Oct 26 16:41:35 2009
+++ src/sys/net/if.c Fri Nov 13 23:11:08 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: if.c,v 1.240 2009/10/26 16:41:35 cegger Exp $ */
+/* $NetBSD: if.c,v 1.241 2009/11/13 23:11:08 joerg Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.240 2009/10/26 16:41:35 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.241 2009/11/13 23:11:08 joerg Exp $");
#include "opt_inet.h"
@@ -1918,20 +1918,14 @@
{
uint8_t len;
u_long ncmd;
- const uint8_t osockspace = sizeof(ifr->ifr_addr);
- const uint8_t sockspace = sizeof(ifr->ifr_ifru.ifru_space);
-#ifdef INET6
- if (cmd == SIOCGIFPSRCADDR_IN6 || cmd == SIOCGIFPDSTADDR_IN6)
- len = MIN(sizeof(struct sockaddr_in6), sa->sa_len);
- else
-#endif /* INET6 */
if ((ncmd = compat_cvtcmd(cmd)) != cmd)
- len = MIN(osockspace, sa->sa_len);
+ len = sizeof(ifr->ifr_addr);
else
- len = MIN(sockspace, sa->sa_len);
+ len = sizeof(ifr->ifr_ifru.ifru_space);
if (len < sa->sa_len)
return EFBIG;
+ memset(&ifr->ifr_addr, 0, len);
sockaddr_copy(&ifr->ifr_addr, len, sa);
return 0;
}