summaryrefslogtreecommitdiff
path: root/include/unistd.h
diff options
context:
space:
mode:
authorsin2015-05-13 12:04:15 +0100
committersin2015-05-13 12:05:29 +0100
commit158782b3bb791eae3c97947944c7023452bfbc96 (patch)
treeb76e70744ab0a2f76d781a65a0456b1b010c54df /include/unistd.h
parent316a48653315b4bc36d8c50b542471b18441c9d5 (diff)
Add fortify_fn() helper in fortify-headers.h
Diffstat (limited to 'include/unistd.h')
-rw-r--r--include/unistd.h73
1 files changed, 25 insertions, 48 deletions
diff --git a/include/unistd.h b/include/unistd.h
index 318fcc5..23a8341 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -4,6 +4,7 @@
4#include_next <unistd.h> 4#include_next <unistd.h>
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#include "fortify-headers.h"
7 8
8#ifdef __cplusplus 9#ifdef __cplusplus
9extern "C" { 10extern "C" {
@@ -21,139 +22,115 @@ extern "C" {
21#undef ttyname_r 22#undef ttyname_r
22#undef write 23#undef write
23 24
24__typeof__(confstr) __confstr_orig __asm__(__USER_LABEL_PREFIX__ "confstr"); 25fortify_fn(confstr) size_t confstr(int name, char *buf, size_t len)
25extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
26size_t confstr(int name, char *buf, size_t len)
27{ 26{
28 size_t bos = __builtin_object_size(buf, 0); 27 size_t bos = __builtin_object_size(buf, 0);
29 28
30 if (len > bos) 29 if (len > bos)
31 __builtin_trap(); 30 __builtin_trap();
32 return __confstr_orig(name, buf, len); 31 return __orig_confstr(name, buf, len);
33} 32}
34 33
35__typeof__(getcwd) __getcwd_orig __asm__(__USER_LABEL_PREFIX__ "getcwd"); 34fortify_fn(getcwd) char *getcwd(char *buf, size_t len)
36extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
37char *getcwd(char *buf, size_t len)
38{ 35{
39 size_t bos = __builtin_object_size(buf, 0); 36 size_t bos = __builtin_object_size(buf, 0);
40 37
41 if (len > bos) 38 if (len > bos)
42 __builtin_trap(); 39 __builtin_trap();
43 return __getcwd_orig(buf, len); 40 return __orig_getcwd(buf, len);
44} 41}
45 42
46#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 43#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
47#undef getdomainname 44#undef getdomainname
48__typeof__(getdomainname) __getdomainname_orig __asm__(__USER_LABEL_PREFIX__ "getdomainname"); 45fortify_fn(getdomainname) int getdomainname(char *name, size_t len)
49extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
50int getdomainname(char *name, size_t len)
51{ 46{
52 size_t bos = __builtin_object_size(name, 0); 47 size_t bos = __builtin_object_size(name, 0);
53 48
54 if (len > bos) 49 if (len > bos)
55 __builtin_trap(); 50 __builtin_trap();
56 return __getdomainname_orig(name, len); 51 return __orig_getdomainname(name, len);
57} 52}
58#endif 53#endif
59 54
60__typeof__(getgroups) __getgroups_orig __asm__(__USER_LABEL_PREFIX__ "getgroups"); 55fortify_fn(getgroups) int getgroups(int len, gid_t *set)
61extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
62int getgroups(int len, gid_t *set)
63{ 56{
64 size_t bos = __builtin_object_size(set, 0); 57 size_t bos = __builtin_object_size(set, 0);
65 58
66 if (len > bos / sizeof(gid_t)) 59 if (len > bos / sizeof(gid_t))
67 __builtin_trap(); 60 __builtin_trap();
68 return __getgroups_orig(len, set); 61 return __orig_getgroups(len, set);
69} 62}
70 63
71__typeof__(gethostname) __gethostname_orig __asm__(__USER_LABEL_PREFIX__ "gethostname"); 64fortify_fn(gethostname) int gethostname(char *name, size_t len)
72extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
73int gethostname(char *name, size_t len)
74{ 65{
75 size_t bos = __builtin_object_size(name, 0); 66 size_t bos = __builtin_object_size(name, 0);
76 67
77 if (len > bos) 68 if (len > bos)
78 __builtin_trap(); 69 __builtin_trap();
79 return __gethostname_orig(name, len); 70 return __orig_gethostname(name, len);
80} 71}
81 72
82__typeof__(getlogin_r) __getlogin_r_orig __asm__(__USER_LABEL_PREFIX__ "getlogin_r"); 73fortify_fn(getlogin_r) int getlogin_r(char *name, size_t len)
83extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
84int getlogin_r(char *name, size_t len)
85{ 74{
86 size_t bos = __builtin_object_size(name, 0); 75 size_t bos = __builtin_object_size(name, 0);
87 76
88 if (len > bos) 77 if (len > bos)
89 __builtin_trap(); 78 __builtin_trap();
90 return __getlogin_r_orig(name, len); 79 return __orig_getlogin_r(name, len);
91} 80}
92 81
93__typeof__(pread) __pread_orig __asm__(__USER_LABEL_PREFIX__ "pread"); 82fortify_fn(pread) ssize_t pread(int fd, void *buf, size_t n, off_t offset)
94extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
95ssize_t pread(int fd, void *buf, size_t n, off_t offset)
96{ 83{
97 size_t bos = __builtin_object_size(buf, 0); 84 size_t bos = __builtin_object_size(buf, 0);
98 85
99 if (n > bos) 86 if (n > bos)
100 __builtin_trap(); 87 __builtin_trap();
101 return __pread_orig(fd, buf, n, offset); 88 return __orig_pread(fd, buf, n, offset);
102} 89}
103 90
104__typeof__(read) __read_orig __asm__(__USER_LABEL_PREFIX__ "read"); 91fortify_fn(read) ssize_t read(int fd, void *buf, size_t n)
105extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
106ssize_t read(int fd, void *buf, size_t n)
107{ 92{
108 size_t bos = __builtin_object_size(buf, 0); 93 size_t bos = __builtin_object_size(buf, 0);
109 94
110 if (n > bos) 95 if (n > bos)
111 __builtin_trap(); 96 __builtin_trap();
112 return __read_orig(fd, buf, n); 97 return __orig_read(fd, buf, n);
113} 98}
114 99
115__typeof__(readlink) __readlink_orig __asm__(__USER_LABEL_PREFIX__ "readlink"); 100fortify_fn(readlink) ssize_t readlink(const char *path, char *buf, size_t n)
116extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
117ssize_t readlink(const char *path, char *buf, size_t n)
118{ 101{
119 size_t bos = __builtin_object_size(buf, 0); 102 size_t bos = __builtin_object_size(buf, 0);
120 103
121 if (n > bos) 104 if (n > bos)
122 __builtin_trap(); 105 __builtin_trap();
123 return __readlink_orig(path, buf, n); 106 return __orig_readlink(path, buf, n);
124} 107}
125 108
126__typeof__(readlinkat) __readlinkat_orig __asm__(__USER_LABEL_PREFIX__ "readlinkat"); 109fortify_fn(readlinkat) ssize_t readlinkat(int fd, const char *path, char *buf, size_t n)
127extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
128ssize_t readlinkat(int fd, const char *path, char *buf, size_t n)
129{ 110{
130 size_t bos = __builtin_object_size(buf, 0); 111 size_t bos = __builtin_object_size(buf, 0);
131 112
132 if (n > bos) 113 if (n > bos)
133 __builtin_trap(); 114 __builtin_trap();
134 return __readlinkat_orig(fd, path, buf, n); 115 return __orig_readlinkat(fd, path, buf, n);
135} 116}
136 117
137__typeof__(ttyname_r) __ttyname_r_orig __asm__(__USER_LABEL_PREFIX__ "ttyname_r"); 118fortify_fn(ttyname_r) int ttyname_r(int fd, char *name, size_t n)
138extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
139int ttyname_r(int fd, char *name, size_t n)
140{ 119{
141 size_t bos = __builtin_object_size(name, 0); 120 size_t bos = __builtin_object_size(name, 0);
142 121
143 if (n > bos) 122 if (n > bos)
144 __builtin_trap(); 123 __builtin_trap();
145 return __ttyname_r_orig(fd, name, n); 124 return __orig_ttyname_r(fd, name, n);
146} 125}
147 126
148__typeof__(write) __write_orig __asm__(__USER_LABEL_PREFIX__ "write"); 127fortify_fn(write) ssize_t write(int fd, const void *buf, size_t n)
149extern __inline __attribute__((__always_inline__,__gnu_inline__,__artificial__))
150ssize_t write(int fd, const void *buf, size_t n)
151{ 128{
152 size_t bos = __builtin_object_size(buf, 0); 129 size_t bos = __builtin_object_size(buf, 0);
153 130
154 if (n > bos) 131 if (n > bos)
155 __builtin_trap(); 132 __builtin_trap();
156 return __write_orig(fd, buf, n); 133 return __orig_write(fd, buf, n);
157} 134}
158 135
159#ifdef __cplusplus 136#ifdef __cplusplus