Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:plunky:20110516185217

Diff

Diff from 1.10 to:

Annotations

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

Annotated File View

plunky
1.10
1 /*      $Id: ssp.c,v 1.10 2011/05/16 18:52:17 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.10
21
22 #ifndef __MSC__
plunky
1.9
23 #include <unistd.h>
plunky
1.10
24 #endif
gmcgarry
1.1
25
gmcgarry
1.3
26 #if defined(__lint__)
27 #define __constructor /* define away */
28 #define __destructor /* define away */
29 #elif defined(__PCC__)
gmcgarry
1.1
30 #define __constructor _Pragma("init")
31 #define __destructor _Pragma("fini")
gmcgarry
1.4
32 #elif defined(__GNUC__)
gmcgarry
1.8
33 #define __constructor __attribute__((constructor))
34 #define __destructor __attribute__((destructor))
gmcgarry
1.4
35 #else
36 #define __constructor
37 #define __destructor
gmcgarry
1.1
38 #endif
39
gmcgarry
1.8
40 #ifdef os_win32
gmcgarry
1.4
41 #define __progname "ERROR"
42 #else
gmcgarry
1.1
43 extern char *__progname;
gmcgarry
1.4
44 #endif
gmcgarry
1.1
45
plunky
1.9
46 void __ssp_init(void);
47 void __stack_chk_fail(void);
48
gmcgarry
1.2
49 int __stack_chk_guard;
gmcgarry
1.1
50
51 void __constructor
52 __ssp_init(void)
53 {
54         int fd;
55         size_t sz;
56
gmcgarry
1.2
57         if (__stack_chk_guard != 0)
gmcgarry
1.1
58                 return;
59
60         fd = open("/dev/urandom"0);
61         if (fd > 0) {
gmcgarry
1.2
62                 sz = read(fd, (char *)&__stack_chk_guard,
63                     sizeof(__stack_chk_guard));
gmcgarry
1.1
64                 close(fd);
gmcgarry
1.2
65                 if (sz == sizeof(__stack_chk_guard))
gmcgarry
1.1
66                         return;
67         }
68
gmcgarry
1.2
69         __stack_chk_guard = 0x00000aff;
gmcgarry
1.1
70 }
71
72 void
gmcgarry
1.2
73 __stack_chk_fail(void)
gmcgarry
1.1
74 {
gmcgarry
1.7
75         static const char msg[] = ": stack smashing attack detected\n";
gmcgarry
1.1
76         write(2__prognamestrlen(__progname));
gmcgarry
1.8
77         write(2msgsizeof(msg) - 1);
gmcgarry
1.1
78         abort();
79 }
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-10-31 00:50 +0100