summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorjlh <jlh@FreeBSD.org>2015-09-22 10:48:28 +0000
committerjlh <jlh@FreeBSD.org>2015-09-22 10:48:28 +0000
commit7699e3299563527ce6b85016b0b4aa8c96883d56 (patch)
tree5928208742a172f0091fc667696ab4c3fe6e943b /lib
parent4d7ca6a717f4b96753cf1c86711931bc890384ef (diff)
downloadFreeBSD-src-7699e3299563527ce6b85016b0b4aa8c96883d56.zip
FreeBSD-src-7699e3299563527ce6b85016b0b4aa8c96883d56.tar.gz
Long overdue MFC r284377:
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
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/sys/stack_protector.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/lib/libc/sys/stack_protector.c b/lib/libc/sys/stack_protector.c
index ed7d635..cd5f166 100644
--- a/lib/libc/sys/stack_protector.c
+++ b/lib/libc/sys/stack_protector.c
@@ -41,8 +41,8 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#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;
OpenPOWER on IntegriCloud