summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorsin2015-02-05 14:03:53 +0000
committersin2015-02-05 14:03:53 +0000
commitaa19847d12f12587937a23e08114e413e6d29ee1 (patch)
tree51970b52cd6ce8781274df53888c6e6796546a8e /include
parent6e4f53a3f50eb987fb5a7657b2ba4eecbfac0557 (diff)
Add confstr() checks
Diffstat (limited to 'include')
-rw-r--r--include/unistd.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/unistd.h b/include/unistd.h
index f930acd..af26474 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -8,6 +8,21 @@
8 8
9#define __errordecl(name, msg) extern void name(void) __attribute__ ((__error__(msg))) 9#define __errordecl(name, msg) extern void name(void) __attribute__ ((__error__(msg)))
10 10
11__errordecl(__confstr_error, "confstr: buffer overflow detected");
12static inline __attribute__ ((always_inline))
13size_t
14__fortify_confstr(int name, char *buf, size_t len)
15{
16 size_t bos = __builtin_object_size(buf, 0);
17
18 if (__builtin_constant_p(len) && len > bos)
19 __confstr_error();
20
21 if (len > bos)
22 __builtin_trap();
23 return confstr(name, buf, len);
24}
25
11__errordecl(__pread_error, "pread: buffer overflow detected"); 26__errordecl(__pread_error, "pread: buffer overflow detected");
12static inline __attribute__ ((always_inline)) 27static inline __attribute__ ((always_inline))
13ssize_t 28ssize_t
@@ -38,6 +53,8 @@ __fortify_read(int fd, void *buf, size_t n)
38 return read(fd, buf, n); 53 return read(fd, buf, n);
39} 54}
40 55
56#undef confstr
57#define confstr(name, buf, len) __fortify_confstr(name, buf, len)
41#undef pread 58#undef pread
42#define pread(fd, buf, n, offset) __fortify_pread(fd, buf, n, offset) 59#define pread(fd, buf, n, offset) __fortify_pread(fd, buf, n, offset)
43#undef read 60#undef read