Module Name:    src
Committed By:   christos
Date:           Sat Nov  6 17:17:13 UTC 2010

Modified Files:
        src/sys/net: if.c

Log Message:
PR/44054: Onno van der Linden: Stacksmashing in handling of ioctl OOSIO*
parameter.


To generate a diff of this commit:
cvs rdiff -u -r1.246 -r1.247 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.246 src/sys/net/if.c:1.247
--- src/sys/net/if.c:1.246	Tue Nov  2 18:34:21 2010
+++ src/sys/net/if.c	Sat Nov  6 13:17:13 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.246 2010/11/02 22:34:21 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.247 2010/11/06 17:17:13 christos 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.246 2010/11/02 22:34:21 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.247 2010/11/06 17:17:13 christos Exp $");
 
 #include "opt_inet.h"
 
@@ -1916,19 +1916,33 @@
 }
 
 int
-ifreq_setaddr(const u_long cmd, struct ifreq *ifr, const struct sockaddr *sa)
+ifreq_setaddr(u_long cmd, struct ifreq *ifr, const struct sockaddr *sa)
 {
 	uint8_t len;
-	u_long ncmd;
-
-	if ((ncmd = compat_cvtcmd(cmd)) != cmd)
-		len = sizeof(ifr->ifr_addr);
-	else
+#ifdef COMPAT_OIFREQ
+	struct ifreq ifrb;
+	struct oifreq *oifr = NULL;
+	u_long ocmd = cmd;
+	cmd = compat_cvtcmd(cmd);
+	if (cmd != ocmd) {
+		oifr = (struct oifreq *)(void *)ifr;
+		ifr = &ifrb;
+		ifreqo2n(oifr, ifr);
+		len = sizeof(oifr->ifr_addr);
+	} else
+#endif
 		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);
+
+#ifdef COMPAT_OIFREQ
+	if (cmd != ocmd)
+		ifreqn2o(oifr, ifr);
+#endif
 	return 0;
 }
 

Reply via email to