From 1dd9d452c5024f35f76c848d652063b9ddb66f47 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Fri, 13 Nov 2009 23:11:08 +0000 Subject: [PATCH] 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@ --- sys/net/if.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index 296b8242efd..df33428de62 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $NetBSD: if.c,v 1.239 2009/10/03 01:46:39 elad Exp $ */ +/* $NetBSD: if.c,v 1.240 2009/10/26 16:41:35 cegger Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.239 2009/10/03 01:46:39 elad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.240 2009/10/26 16:41:35 cegger Exp $"); #include "opt_inet.h" @@ -1918,20 +1918,14 @@ ifreq_setaddr(const u_long cmd, struct ifreq *ifr, const struct sockaddr *sa) { 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; } -- 2.11.4.GIT