diff options
| author | sin | 2015-02-24 19:04:02 +0000 |
|---|---|---|
| committer | sin | 2015-02-24 19:04:02 +0000 |
| commit | f05c09fac82907ed0f05adaffe10c3832a245297 (patch) | |
| tree | aad12a3fda90221e3f8eea050ecbcf28cfbb7d2f | |
| parent | eecef18261cc278fbc13ecbfb4e5bc10762cc794 (diff) | |
Add realpath() check
| -rw-r--r-- | include/stdlib.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/include/stdlib.h b/include/stdlib.h new file mode 100644 index 0000000..2948b54 --- /dev/null +++ b/include/stdlib.h | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | #ifndef FORTIFY_STDLIB_H_ | ||
| 2 | #define FORTIFY_STDLIB_H_ | ||
| 3 | |||
| 4 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 5 | || defined(_BSD_SOURCE) | ||
| 6 | #include_next <limits.h> | ||
| 7 | #endif | ||
| 8 | |||
| 9 | #include_next <stdlib.h> | ||
| 10 | |||
| 11 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 | ||
| 12 | |||
| 13 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 14 | || defined(_BSD_SOURCE) | ||
| 15 | static inline __attribute__ ((always_inline)) | ||
| 16 | char * | ||
| 17 | __fortify_realpath(const char *path, char *resolved) | ||
| 18 | { | ||
| 19 | size_t bos; | ||
| 20 | |||
| 21 | if (resolved) { | ||
| 22 | bos = __builtin_object_size(resolved, 0); | ||
| 23 | if (PATH_MAX > bos) | ||
| 24 | __builtin_trap(); | ||
| 25 | } | ||
| 26 | return realpath(path, resolved); | ||
| 27 | } | ||
| 28 | |||
| 29 | #undef realpath | ||
| 30 | #define realpath(path, resolved) __fortify_realpath(path, resolved) | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #endif | ||
| 34 | |||
| 35 | #endif | ||
