- bzero(&sa, sizeof(struct sigaction));
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = 0;
- sa.sa_handler = SIG_DFL;
- sigaction(SIGABRT, &sa, NULL);
+ fd = open ("/dev/urandom", 0);
+ if (fd != -1) {
+ len = read (fd, (char*)&__stack_chk_guard, sizeof(__stack_chk_guard));
+ close(fd);
+ if (len == sizeof(__stack_chk_guard) &&
+ *__stack_chk_guard != 0)
+ return;
+ }
+
+ /* If If a random generator can't be used, the protector switches the guard
+ to the "terminator canary" */
+ ((unsigned char *)__stack_chk_guard)[0] = 0;
+ ((unsigned char *)__stack_chk_guard)[1] = 0;
+ ((unsigned char *)__stack_chk_guard)[2] = '\n';
+ ((unsigned char *)__stack_chk_guard)[3] = 255;
+}
+
+static const char *stackoverflow_msg = "stack buffer overflow";
+
+void
+__stack_chk_fail()
+{
+ CRSetCrashLogMessage(stackoverflow_msg);