From owner-svn-src-head@FreeBSD.ORG Sun Jun 14 07:47:19 2015 Return-Path: Delivered-To: svn-src-head@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id AAFE2B77; Sun, 14 Jun 2015 07:47:19 +0000 (UTC) (envelope-from jlh@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7F39CD49; Sun, 14 Jun 2015 07:47:19 +0000 (UTC) (envelope-from jlh@FreeBSD.org) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t5E7lJBC029407; Sun, 14 Jun 2015 07:47:19 GMT (envelope-from jlh@FreeBSD.org) Received: (from jlh@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t5E7lJvh029406; Sun, 14 Jun 2015 07:47:19 GMT (envelope-from jlh@FreeBSD.org) Message-Id: <201506140747.t5E7lJvh029406@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: jlh set sender to jlh@FreeBSD.org using -f From: Jeremie Le Hen Date: Sun, 14 Jun 2015 07:47:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r284377 - head/lib/libc/sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Jun 2015 07:47:19 -0000 Author: jlh Date: Sun Jun 14 07:47:18 2015 New Revision: 284377 URL: https://svnweb.freebsd.org/changeset/base/284377 Log: NetBSD commit log: 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. I'm not sure why this hasn't bitten us yes, but it is certainly possible and there are no real drawbacks to this change anyway. Submitted by: pfg Obtained from: NetBSD MFC after: 1 week Modified: head/lib/libc/sys/stack_protector.c Modified: head/lib/libc/sys/stack_protector.c ============================================================================== --- head/lib/libc/sys/stack_protector.c Sun Jun 14 05:23:39 2015 (r284376) +++ head/lib/libc/sys/stack_protector.c Sun Jun 14 07:47:18 2015 (r284377) @@ -41,8 +41,8 @@ __FBSDID("$FreeBSD$"); #include #include "libc_private.h" -extern int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, - void *newp, size_t newlen); +extern int __sysctl(const int *name, u_int namelen, void *oldp, + size_t *oldlenp, void *newp, size_t newlen); long __stack_chk_guard[8] = {0, 0, 0, 0, 0, 0, 0, 0}; static void __guard_setup(void) __attribute__((__constructor__, __used__)); @@ -54,7 +54,7 @@ void __chk_fail(void); static void __guard_setup(void) { - int mib[2]; + static const int mib[2] = { CTL_KERN, KERN_ARND }; size_t len; int error; @@ -65,12 +65,9 @@ __guard_setup(void) if (error == 0 && __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 || - len != sizeof(__stack_chk_guard)) { + if (__sysctl(mib, nitems(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; ((unsigned char *)(void *)__stack_chk_guard)[1] = 0;