diff options
| author | sin | 2015-01-29 10:43:00 +0000 |
|---|---|---|
| committer | sin | 2015-01-29 10:43:09 +0000 |
| commit | 52d4c979802345f03193258af7f120de4bcae1ff (patch) | |
| tree | 5539cf8b28109ac1f4fd9c9a422e61c5a32bdb53 /include | |
| parent | 2f6dc9f34ff30887dd81d98e7e2a2b7e7ff8b431 (diff) | |
Add bcopy() checks
Diffstat (limited to 'include')
| -rw-r--r-- | include/strings.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/include/strings.h b/include/strings.h new file mode 100644 index 0000000..db08cc9 --- /dev/null +++ b/include/strings.h | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | #ifndef FORTIFY_STRINGS_H_ | ||
| 2 | #define FORTIFY_STRINGS_H_ | ||
| 3 | |||
| 4 | #include_next <strings.h> | ||
| 5 | |||
| 6 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 | ||
| 7 | |||
| 8 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ | ||
| 9 | || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ | ||
| 10 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) | ||
| 11 | |||
| 12 | static inline __attribute__ ((always_inline)) | ||
| 13 | void __fortify_bcopy(const void *__restrict src, void *__restrict dest, size_t n) | ||
| 14 | { | ||
| 15 | size_t bos = __builtin_object_size(dest, 0); | ||
| 16 | |||
| 17 | if (n > bos) | ||
| 18 | __builtin_trap(); | ||
| 19 | return bcopy(src, dest, n); | ||
| 20 | } | ||
| 21 | |||
| 22 | #undef bcopy | ||
| 23 | #define bcopy(src, dest, n) __fortify_bcopy(src, dest, n) | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #endif | ||
| 27 | |||
| 28 | #endif | ||
