Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/misc Use a constant array for the MIB. Newer LLVM d...



details:   https://anonhg.NetBSD.org/src/rev/2cf7333a465b
branches:  trunk
changeset: 771913:2cf7333a465b
user:      joerg <joerg%NetBSD.org@localhost>
date:      Thu Dec 08 02:27:14 2011 +0000

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

diffstat:

 lib/libc/misc/stack_protector.c |  11 ++++-------
 1 files changed, 4 insertions(+), 7 deletions(-)

diffs (38 lines):

diff -r 86e7cacdb9cb -r 2cf7333a465b lib/libc/misc/stack_protector.c
--- a/lib/libc/misc/stack_protector.c   Thu Dec 08 01:15:02 2011 +0000
+++ b/lib/libc/misc/stack_protector.c   Thu Dec 08 02:27:14 2011 +0000
@@ -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;



Home | Main Index | Thread Index | Old Index