Thu Dec 8 02:27:14 2011 UTC ()
Use a constant array for the MIB. Newer LLVM decided that mib[] warranted
stack protections, with the obvious crash after the setup was done.
As a positive side effect, code size shrinks a bit.


(joerg)
diff -r1.6 -r1.7 src/lib/libc/misc/stack_protector.c

cvs diff -r1.6 -r1.7 src/lib/libc/misc/stack_protector.c (expand / switch to context diff)
--- src/lib/libc/misc/stack_protector.c 2011/09/16 16:05:59 1.6
+++ src/lib/libc/misc/stack_protector.c 2011/12/08 02:27:14 1.7
@@ -1,4 +1,4 @@
-/*	$NetBSD: stack_protector.c,v 1.6 2011/09/16 16:05:59 joerg Exp $	*/
+/*	$NetBSD: stack_protector.c,v 1.7 2011/12/08 02:27:14 joerg Exp $	*/
 /*	$OpenBSD: stack_protector.c,v 1.10 2006/03/31 05:34:44 deraadt Exp $	*/
 
 /*
@@ -28,7 +28,7 @@
  *
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: stack_protector.c,v 1.6 2011/09/16 16:05:59 joerg Exp $");
+__RCSID("$NetBSD: stack_protector.c,v 1.7 2011/12/08 02:27:14 joerg Exp $");
 
 #ifdef _LIBC
 #include "namespace.h"
@@ -56,17 +56,14 @@
 void
 __guard_setup(void)
 {
-	int mib[2];
+	static const int mib[2] = { CTL_KERN, KERN_ARND };
 	size_t len;
 
 	if (__stack_chk_guard[0] != 0)
 		return;
 
-	mib[0] = CTL_KERN;
-	mib[1] = KERN_ARND;
-
 	len = sizeof(__stack_chk_guard);
-	if (__sysctl(mib, 2, __stack_chk_guard, &len, NULL, 0) == -1 ||
+	if (__sysctl(mib, __arraycount(mib), __stack_chk_guard, &len, NULL, 0) == -1 ||
 	    len != sizeof(__stack_chk_guard)) {
 		/* If sysctl was unsuccessful, use the "terminator canary". */
 		((unsigned char *)(void *)__stack_chk_guard)[0] = 0;