summaryrefslogtreecommitdiff
path: root/include/unistd.h
diff options
context:
space:
mode:
authorsin2015-02-05 14:07:14 +0000
committersin2015-02-05 14:07:14 +0000
commit00b376bb073b39f202db6f8080010a2812dde08b (patch)
tree0c65c064a54b6c8a1d65ec52e0fef47854a750d4 /include/unistd.h
parentaa19847d12f12587937a23e08114e413e6d29ee1 (diff)
Add getcwd() checks
Diffstat (limited to 'include/unistd.h')
-rw-r--r--include/unistd.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/unistd.h b/include/unistd.h
index af26474..60fb933 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -23,6 +23,21 @@ __fortify_confstr(int name, char *buf, size_t len)
23 return confstr(name, buf, len); 23 return confstr(name, buf, len);
24} 24}
25 25
26__errordecl(__getcwd_error, "getcwd: buffer overflow detected");
27static inline __attribute__ ((always_inline))
28char *
29__fortify_getcwd(char *buf, size_t len)
30{
31 size_t bos = __builtin_object_size(buf, 0);
32
33 if (__builtin_constant_p(len) && len > bos)
34 __getcwd_error();
35
36 if (len > bos)
37 __builtin_trap();
38 return getcwd(buf, len);
39}
40
26__errordecl(__pread_error, "pread: buffer overflow detected"); 41__errordecl(__pread_error, "pread: buffer overflow detected");
27static inline __attribute__ ((always_inline)) 42static inline __attribute__ ((always_inline))
28ssize_t 43ssize_t
@@ -55,6 +70,8 @@ __fortify_read(int fd, void *buf, size_t n)
55 70
56#undef confstr 71#undef confstr
57#define confstr(name, buf, len) __fortify_confstr(name, buf, len) 72#define confstr(name, buf, len) __fortify_confstr(name, buf, len)
73#undef getcwd
74#define getcwd(buf, len) __fortify_getcwd(buf, len)
58#undef pread 75#undef pread
59#define pread(fd, buf, n, offset) __fortify_pread(fd, buf, n, offset) 76#define pread(fd, buf, n, offset) __fortify_pread(fd, buf, n, offset)
60#undef read 77#undef read