- int fd;
- if (__stack_chk_guard[0]!=0) return;
- fd = open ("/dev/urandom", 0);
- if (fd != -1) {
- ssize_t size = read (fd, (char*)&__stack_chk_guard,
- sizeof(__stack_chk_guard));
- close (fd) ;
- 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*)__stack_chk_guard)[0] = 0; ((char*)__stack_chk_guard)[1] = 0;
- ((char*)__stack_chk_guard)[2] = '\n'; ((char*)__stack_chk_guard)[3] = 255;
+ int fd;
+ size_t len;
+ const char **p;
+
+ if (__stack_chk_guard[0] != 0)
+ return;
+
+ for (p = apple; p && *p; p++) {
+ if (strstr(*p, "stack_guard") == *p) {
+ __guard_from_kernel(*p);
+ if (__stack_chk_guard[0] != 0)
+ return;
+ }
+ }
+
+ 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;