diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2005-11-30 07:51:03 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2005-11-30 07:51:03 +0000 |
commit | 1fcb44d8d6accf4b13417c63d21bd922f79d386a (patch) | |
tree | d5f0eb26e09410e4bf7f6d954c2e138b95ccd125 /lib/libc/sys | |
parent | 0f97be5213bc1c35042f4403759d8c954c4e631a (diff) |
Use sysctl(KERN_ARND) to get n bytes, instead of just 4 at a time
and remove fallback code. If somebody is dumb enough to make the
sysctl fail using systrace, he deserves what he gets. Saves 7 syscalls
on process startup.
looks good miod@ ok deraadt@ tedu@
Diffstat (limited to 'lib/libc/sys')
-rw-r--r-- | lib/libc/sys/stack_protector.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/lib/libc/sys/stack_protector.c b/lib/libc/sys/stack_protector.c index 1f9050f65ce..a89b1d8c832 100644 --- a/lib/libc/sys/stack_protector.c +++ b/lib/libc/sys/stack_protector.c @@ -1,4 +1,4 @@ -/* $OpenBSD: stack_protector.c,v 1.8 2005/08/08 08:05:37 espie Exp $ */ +/* $OpenBSD: stack_protector.c,v 1.9 2005/11/30 07:51:02 otto Exp $ */ /* * Copyright (c) 2002 Hiroaki Etoh, Federico G. Schwindt, and Miodrag Vallat. @@ -43,7 +43,7 @@ void __stack_smash_handler(char func[], int damaged __attribute__((unused))); static void __guard_setup(void) { - int i, mib[2]; + int mib[2]; size_t len; if (__guard[0] != 0) @@ -52,14 +52,9 @@ __guard_setup(void) mib[0] = CTL_KERN; mib[1] = KERN_ARND; - len = 4; - for (i = 0; i < sizeof(__guard) / 4; i++) { - if (__sysctl(mib, 2, (char *)&((int *)__guard)[i], - &len, NULL, 0) == -1) - break; - } - - if (i < sizeof(__guard) / 4) { + len = sizeof(__guard); + if (__sysctl(mib, 2, __guard, &len, NULL, 0) == -1 || + len != sizeof(__guard)) { /* If sysctl was unsuccessful, use the "terminator canary". */ ((unsigned char *)__guard)[0] = 0; ((unsigned char *)__guard)[1] = 0; |