X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/c957a83bde4df2e2d3d1ed0963656856b48ef0a0..224c70764cab4e0e39a26aaf3ad3016552f62f55:/sys/OpenBSD/stack_protector.c.patch?ds=sidebyside diff --git a/sys/OpenBSD/stack_protector.c.patch b/sys/OpenBSD/stack_protector.c.patch index 64c5df1..e6766cc 100644 --- a/sys/OpenBSD/stack_protector.c.patch +++ b/sys/OpenBSD/stack_protector.c.patch @@ -1,15 +1,69 @@ ---- stack_protector.c.orig 2006-10-05 00:09:07.000000000 -0700 -+++ stack_protector.c 2006-10-05 00:18:28.000000000 -0700 -@@ -34,10 +34,10 @@ +Index: stack_protector.c +=================================================================== +--- stack_protector.c (revision 31377) ++++ stack_protector.c (working copy) +@@ -32,44 +32,41 @@ static char rcsid[] = "$OpenBSD: stack_p + #include + #include #include ++#include ++#include ++#include ++ ++extern void __abort(void) __dead2; ++long __stack_chk_guard[8] = {0, 0, 0, 0, 0, 0, 0, 0}; ++void __guard_setup(void) __attribute__ ((visibility ("hidden"))); ++void __stack_chk_fail(void); - long __guard[8] = {0, 0, 0, 0, 0, 0, 0, 0}; +-long __guard[8] = {0, 0, 0, 0, 0, 0, 0, 0}; -static void __guard_setup(void) __attribute__ ((constructor)); -+__private_extern__ void __guard_setup(void); - void __stack_smash_handler(char func[], int damaged __attribute__((unused))); - +-void __stack_smash_handler(char func[], int damaged __attribute__((unused))); +- -static void -+__private_extern__ void ++void __guard_setup(void) { int fd; +- if (__guard[0]!=0) return; ++ if (__stack_chk_guard[0]!=0) return; + fd = open ("/dev/urandom", 0); + if (fd != -1) { +- ssize_t size = read (fd, (char*)&__guard, sizeof(__guard)); ++ ssize_t size = read (fd, (char*)&__stack_chk_guard, ++ sizeof(__stack_chk_guard)); + close (fd) ; +- if (size == sizeof(__guard)) return; ++ if (size == sizeof(__stack_chk_guard) ++ && *__stack_chk_guard != 0) return; + } + /* If a random generator can't be used, the protector switches the guard + to the "terminator canary" */ +- ((char*)__guard)[0] = 0; ((char*)__guard)[1] = 0; +- ((char*)__guard)[2] = '\n'; ((char*)__guard)[3] = 255; ++ ((char*)__stack_chk_guard)[0] = 0; ((char*)__stack_chk_guard)[1] = 0; ++ ((char*)__stack_chk_guard)[2] = '\n'; ((char*)__stack_chk_guard)[3] = 255; + } + + void +-__stack_smash_handler(char func[], int damaged) ++__stack_chk_fail() + { +- const char message[] = "stack overflow in function %s"; +- struct sigaction sa; ++ const char message[] = "[%d] stack overflow"; + + /* this may fail on a chroot jail, though luck */ +- syslog(LOG_CRIT, message, func); +- +- bzero(&sa, sizeof(struct sigaction)); +- sigemptyset(&sa.sa_mask); +- sa.sa_flags = 0; +- sa.sa_handler = SIG_DFL; +- sigaction(SIGABRT, &sa, NULL); +- +- kill(getpid(), SIGABRT); ++ syslog(LOG_CRIT, message, getpid()); + +- _exit(127); ++ __abort(); + }