Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:plunky:20110515085751

Diff

Diff from 1.9 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/pcc/pcc-libs/libpcc/ssp.c

Annotated File View

plunky
1.9
1 /*      $Id: ssp.c,v 1.9 2011/05/15 08:57:51 plunky Exp $       */
gmcgarry
1.1
2 /*-
3  * Copyright (c) 2008 Gregory McGarry <g.mcgarry@ieee.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17
plunky
1.9
18 #include <fcntl.h>
gmcgarry
1.1
19 #include <stdlib.h>
20 #include <string.h>
plunky
1.9
21 #include <unistd.h>
gmcgarry
1.1
22
gmcgarry
1.3
23 #if defined(__lint__)
24 #define __constructor /* define away */
25 #define __destructor /* define away */
26 #elif defined(__PCC__)
gmcgarry
1.1
27 #define __constructor _Pragma("init")
28 #define __destructor _Pragma("fini")
gmcgarry
1.4
29 #elif defined(__GNUC__)
gmcgarry
1.8
30 #define __constructor __attribute__((constructor))
31 #define __destructor __attribute__((destructor))
gmcgarry
1.4
32 #else
33 #define __constructor
34 #define __destructor
gmcgarry
1.1
35 #endif
36
gmcgarry
1.8
37 #ifdef os_win32
gmcgarry
1.4
38 #define __progname "ERROR"
39 #else
gmcgarry
1.1
40 extern char *__progname;
gmcgarry
1.4
41 #endif
gmcgarry
1.1
42
plunky
1.9
43 void __ssp_init(void);
44 void __stack_chk_fail(void);
45
gmcgarry
1.2
46 int __stack_chk_guard;
gmcgarry
1.1
47
48 void __constructor
49 __ssp_init(void)
50 {
51         int fd;
52         size_t sz;
53
gmcgarry
1.2
54         if (__stack_chk_guard != 0)
gmcgarry
1.1
55                 return;
56
57         fd = open("/dev/urandom"0);
58         if (fd > 0) {
gmcgarry
1.2
59                 sz = read(fd, (char *)&__stack_chk_guard,
60                     sizeof(__stack_chk_guard));
gmcgarry
1.1
61                 close(fd);
gmcgarry
1.2
62                 if (sz == sizeof(__stack_chk_guard))
gmcgarry
1.1
63                         return;
64         }
65
gmcgarry
1.2
66         __stack_chk_guard = 0x00000aff;
gmcgarry
1.1
67 }
68
69 void
gmcgarry
1.2
70 __stack_chk_fail(void)
gmcgarry
1.1
71 {
gmcgarry
1.7
72         static const char msg[] = ": stack smashing attack detected\n";
gmcgarry
1.1
73         write(2__prognamestrlen(__progname));
gmcgarry
1.8
74         write(2msgsizeof(msg) - 1);
gmcgarry
1.1
75         abort();
76 }
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-07-10 07:06 +0200