diff options
| author | sin | 2015-02-05 14:03:53 +0000 |
|---|---|---|
| committer | sin | 2015-02-05 14:03:53 +0000 |
| commit | aa19847d12f12587937a23e08114e413e6d29ee1 (patch) | |
| tree | 51970b52cd6ce8781274df53888c6e6796546a8e /include/unistd.h | |
| parent | 6e4f53a3f50eb987fb5a7657b2ba4eecbfac0557 (diff) | |
Add confstr() checks
Diffstat (limited to 'include/unistd.h')
| -rw-r--r-- | include/unistd.h | 17 |
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"); | ||
| 12 | static inline __attribute__ ((always_inline)) | ||
| 13 | size_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"); |
| 12 | static inline __attribute__ ((always_inline)) | 27 | static inline __attribute__ ((always_inline)) |
| 13 | ssize_t | 28 | ssize_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 |
