summaryrefslogtreecommitdiff
path: root/include/unistd.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/unistd.h24
1 files changed, 0 insertions, 24 deletions
diff --git a/include/unistd.h b/include/unistd.h
index bffccf7..b13b507 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -5,78 +5,56 @@
5 5
6#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 6#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
7 7
8#define __errordecl(name, msg) extern void name(void) __attribute__ ((__error__(msg)))
9
10__errordecl(__confstr_error, "confstr: buffer overflow detected");
11static inline __attribute__ ((always_inline)) 8static inline __attribute__ ((always_inline))
12size_t 9size_t
13__fortify_confstr(int name, char *buf, size_t len) 10__fortify_confstr(int name, char *buf, size_t len)
14{ 11{
15 size_t bos = __builtin_object_size(buf, 0); 12 size_t bos = __builtin_object_size(buf, 0);
16 13
17 if (__builtin_constant_p(len) && len > bos)
18 __confstr_error();
19
20 if (len > bos) 14 if (len > bos)
21 __builtin_trap(); 15 __builtin_trap();
22 return confstr(name, buf, len); 16 return confstr(name, buf, len);
23} 17}
24 18
25__errordecl(__getcwd_error, "getcwd: buffer overflow detected");
26static inline __attribute__ ((always_inline)) 19static inline __attribute__ ((always_inline))
27char * 20char *
28__fortify_getcwd(char *buf, size_t len) 21__fortify_getcwd(char *buf, size_t len)
29{ 22{
30 size_t bos = __builtin_object_size(buf, 0); 23 size_t bos = __builtin_object_size(buf, 0);
31 24
32 if (__builtin_constant_p(len) && len > bos)
33 __getcwd_error();
34
35 if (len > bos) 25 if (len > bos)
36 __builtin_trap(); 26 __builtin_trap();
37 return getcwd(buf, len); 27 return getcwd(buf, len);
38} 28}
39 29
40__errordecl(__gethostname_error, "gethostname: buffer overflow detected");
41static inline __attribute__ ((always_inline)) 30static inline __attribute__ ((always_inline))
42int 31int
43__fortify_gethostname(char *name, size_t len) 32__fortify_gethostname(char *name, size_t len)
44{ 33{
45 size_t bos = __builtin_object_size(name, 0); 34 size_t bos = __builtin_object_size(name, 0);
46 35
47 if (__builtin_constant_p(len) && len > bos)
48 __gethostname_error();
49
50 if (len > bos) 36 if (len > bos)
51 __builtin_trap(); 37 __builtin_trap();
52 return gethostname(name, len); 38 return gethostname(name, len);
53} 39}
54 40
55__errordecl(__pread_error, "pread: buffer overflow detected");
56static inline __attribute__ ((always_inline)) 41static inline __attribute__ ((always_inline))
57ssize_t 42ssize_t
58__fortify_pread(int fd, void *buf, size_t n, off_t offset) 43__fortify_pread(int fd, void *buf, size_t n, off_t offset)
59{ 44{
60 size_t bos = __builtin_object_size(buf, 0); 45 size_t bos = __builtin_object_size(buf, 0);
61 46
62 if (__builtin_constant_p(n) && n > bos)
63 __pread_error();
64
65 if (n > bos) 47 if (n > bos)
66 __builtin_trap(); 48 __builtin_trap();
67 return pread(fd, buf, n, offset); 49 return pread(fd, buf, n, offset);
68} 50}
69 51
70__errordecl(__read_error, "read: buffer overflow detected");
71static inline __attribute__ ((always_inline)) 52static inline __attribute__ ((always_inline))
72ssize_t 53ssize_t
73__fortify_read(int fd, void *buf, size_t n) 54__fortify_read(int fd, void *buf, size_t n)
74{ 55{
75 size_t bos = __builtin_object_size(buf, 0); 56 size_t bos = __builtin_object_size(buf, 0);
76 57
77 if (__builtin_constant_p(n) && n > bos)
78 __read_error();
79
80 if (n > bos) 58 if (n > bos)
81 __builtin_trap(); 59 __builtin_trap();
82 return read(fd, buf, n); 60 return read(fd, buf, n);
@@ -93,8 +71,6 @@ __fortify_read(int fd, void *buf, size_t n)
93#undef read 71#undef read
94#define read(fd, buf, n) __fortify_read(fd, buf, n) 72#define read(fd, buf, n) __fortify_read(fd, buf, n)
95 73
96#undef __errordecl
97
98#endif 74#endif
99 75
100#endif 76#endif