summaryrefslogtreecommitdiff
blob: d037cd103e93a51e9601afa17fa1215ba7415226 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
diff -u -r -N gcc-3.2.3.ORIG/gcc/libgcc-std.ver gcc-3.2.3/gcc/libgcc-std.ver
--- gcc-3.2.3.ORIG/gcc/libgcc-std.ver	2003-11-11 18:12:52.000000000 +0100
+++ gcc-3.2.3/gcc/libgcc-std.ver	2003-11-11 18:19:31.000000000 +0100
@@ -176,6 +176,7 @@
   _Unwind_SjLj_Resume
 
   # stack smash handler symbols
-  __guard
-  __stack_smash_handler
+  # these can be found in glibc now
+  # __guard
+  # __stack_smash_handler
 }
diff -u -r -N gcc-3.2.3.ORIG/gcc/libgcc2.c gcc-3.2.3/gcc/libgcc2.c
--- gcc-3.2.3.ORIG/gcc/libgcc2.c	2003-11-11 18:12:52.000000000 +0100
+++ gcc-3.2.3/gcc/libgcc2.c	2003-11-11 18:20:44.000000000 +0100
@@ -2052,100 +2052,7 @@
 #endif /* L_exit */
 
 #ifdef L_stack_smash_handler
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#ifdef _POSIX_SOURCE
-#include <signal.h>
-#endif
-
-#if defined(HAVE_SYSLOG)
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-
-#include <sys/syslog.h>
-#ifndef _PATH_LOG
-#define _PATH_LOG "/dev/log"
-#endif
-#endif
-
-long __guard[8] = {0,0,0,0,0,0,0,0};
-static void __guard_setup (void) __attribute__ ((constructor)) ;
-static void __guard_setup (void)
-{
-  int fd;
-  if (__guard[0]!=0) return;
-  fd = open ("/dev/urandom", 0);
-  if (fd != -1) {
-    ssize_t size = read (fd, (char*)&__guard, sizeof(__guard));
-    close (fd) ;
-    if (size == sizeof(__guard)) 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;
-}
-void __stack_smash_handler (char func[], int damaged ATTRIBUTE_UNUSED)
-{
-#if defined (__GNU_LIBRARY__)
-  extern char * __progname;
-#endif
-  const char message[] = ": stack smashing attack in function ";
-  int bufsz = 256, len;
-  char buf[bufsz];
-#if defined(HAVE_SYSLOG)
-  int LogFile;
-  struct sockaddr_un SyslogAddr;  /* AF_UNIX address of local logger */
-#endif
-#ifdef _POSIX_SOURCE
-  {
-    sigset_t mask;
-    sigfillset(&mask);
-    sigdelset(&mask, SIGABRT);	/* Block all signal handlers */
-    sigprocmask(SIG_BLOCK, &mask, NULL); /* except SIGABRT */
-  }
-#endif
-
-  strcpy(buf, "<2>"); len=3;	/* send LOG_CRIT */
-#if defined (__GNU_LIBRARY__)
-  strncat(buf, __progname, bufsz-len-1); len = strlen(buf);
-#endif
-  if (bufsz>len) {strncat(buf, message, bufsz-len-1); len = strlen(buf);}
-  if (bufsz>len) {strncat(buf, func, bufsz-len-1); len = strlen(buf);}
-
-  /* print error message */
-  write (STDERR_FILENO, buf+3, len-3);
-#if defined(HAVE_SYSLOG)
-  if ((LogFile = socket(AF_UNIX, SOCK_DGRAM, 0)) != -1) {
-
-    /*
-     * Send "found" message to the "/dev/log" path
-     */
-    SyslogAddr.sun_family = AF_UNIX;
-    (void)strncpy(SyslogAddr.sun_path, _PATH_LOG,
-		  sizeof(SyslogAddr.sun_path) - 1);
-    SyslogAddr.sun_path[sizeof(SyslogAddr.sun_path) - 1] = '\0';
-    sendto(LogFile, buf, len, 0, (struct sockaddr *)&SyslogAddr,
-	   sizeof(SyslogAddr));
-  }
-#endif
-
-#ifdef _POSIX_SOURCE
-  { /* Make sure the default handler is associated with SIGABRT */
-    struct sigaction sa;
-    
-    memset(&sa, 0, sizeof(struct sigaction));
-    sigfillset(&sa.sa_mask);	/* Block all signals */
-    sa.sa_flags = 0;
-    sa.sa_handler = SIG_DFL;
-    sigaction(SIGABRT, &sa, NULL);
-    (void)kill(getpid(), SIGABRT);
-  }
-#endif
-  _exit(127);
-}
+extern long __guard[8];
+extern void __guard_setup (void);
+extern void __stack_smash_handler (char func[], int damaged);
 #endif