diff options
Diffstat (limited to '')
| -rw-r--r-- | include/unistd.h | 24 |
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"); | ||
| 11 | static inline __attribute__ ((always_inline)) | 8 | static inline __attribute__ ((always_inline)) |
| 12 | size_t | 9 | size_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"); | ||
| 26 | static inline __attribute__ ((always_inline)) | 19 | static inline __attribute__ ((always_inline)) |
| 27 | char * | 20 | char * |
| 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"); | ||
| 41 | static inline __attribute__ ((always_inline)) | 30 | static inline __attribute__ ((always_inline)) |
| 42 | int | 31 | int |
| 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"); | ||
| 56 | static inline __attribute__ ((always_inline)) | 41 | static inline __attribute__ ((always_inline)) |
| 57 | ssize_t | 42 | ssize_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"); | ||
| 71 | static inline __attribute__ ((always_inline)) | 52 | static inline __attribute__ ((always_inline)) |
| 72 | ssize_t | 53 | ssize_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 |
