Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:gmcgarry:20110517001919

Diff

Diff from 1.11 to:

Annotations

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

Annotated File View

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