diff options
| author | sin | 2015-02-05 14:07:14 +0000 |
|---|---|---|
| committer | sin | 2015-02-05 14:07:14 +0000 |
| commit | 00b376bb073b39f202db6f8080010a2812dde08b (patch) | |
| tree | 0c65c064a54b6c8a1d65ec52e0fef47854a750d4 | |
| parent | aa19847d12f12587937a23e08114e413e6d29ee1 (diff) | |
Add getcwd() checks
| -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 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"); | ||
| 27 | static inline __attribute__ ((always_inline)) | ||
| 28 | char * | ||
| 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"); |
| 27 | static inline __attribute__ ((always_inline)) | 42 | static inline __attribute__ ((always_inline)) |
| 28 | ssize_t | 43 | ssize_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 |
