Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Simplify ifreq_setaddr:



details:   https://anonhg.NetBSD.org/src/rev/12c6e6904835
branches:  trunk
changeset: 749022:12c6e6904835
user:      joerg <joerg%NetBSD.org@localhost>
date:      Fri Nov 13 23:11:08 2009 +0000

description:
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@

diffstat:

 sys/net/if.c |  18 ++++++------------
 1 files changed, 6 insertions(+), 12 deletions(-)

diffs (43 lines):

diff -r 1a74cd2844e6 -r 12c6e6904835 sys/net/if.c
--- a/sys/net/if.c      Fri Nov 13 22:49:46 2009 +0000
+++ b/sys/net/if.c      Fri Nov 13 23:11:08 2009 +0000
@@ -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);
+       if ((ncmd = compat_cvtcmd(cmd)) != cmd)
+               len = sizeof(ifr->ifr_addr);
        else
-#endif /* INET6 */
-       if ((ncmd = compat_cvtcmd(cmd)) != cmd)
-               len = MIN(osockspace, sa->sa_len);
-       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;
 }



Home | Main Index | Thread Index | Old Index