diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/fortify-headers.h | 7 | ||||
| -rw-r--r-- | include/stdlib.h | 23 |
2 files changed, 30 insertions, 0 deletions
diff --git a/include/fortify-headers.h b/include/fortify-headers.h index 2f81fc0..dde19a2 100644 --- a/include/fortify-headers.h +++ b/include/fortify-headers.h | |||
| @@ -78,6 +78,13 @@ | |||
| 78 | #define __malloc(...) | 78 | #define __malloc(...) |
| 79 | #endif | 79 | #endif |
| 80 | 80 | ||
| 81 | #if __has_attribute (alloc_size) | ||
| 82 | #define __alloc_size(...) __attribute__ ((alloc_size (__VA_ARGS__))) | ||
| 83 | #else | ||
| 84 | #define __alloc_size(...) | ||
| 85 | #endif | ||
| 86 | |||
| 87 | |||
| 81 | #endif /* __has_attribute */ | 88 | #endif /* __has_attribute */ |
| 82 | 89 | ||
| 83 | 90 | ||
diff --git a/include/stdlib.h b/include/stdlib.h index b661862..6914f02 100644 --- a/include/stdlib.h +++ b/include/stdlib.h | |||
| @@ -37,13 +37,36 @@ extern "C" { | |||
| 37 | #endif | 37 | #endif |
| 38 | 38 | ||
| 39 | #undef malloc | 39 | #undef malloc |
| 40 | #undef realloc | ||
| 40 | 41 | ||
| 41 | __malloc(malloc (free, 1)) | 42 | __malloc(malloc (free, 1)) |
| 43 | __alloc_size(1) | ||
| 42 | _FORTIFY_FN(malloc) void *malloc(size_t __s) | 44 | _FORTIFY_FN(malloc) void *malloc(size_t __s) |
| 43 | { | 45 | { |
| 44 | return __orig_malloc(__s); | 46 | return __orig_malloc(__s); |
| 45 | } | 47 | } |
| 46 | 48 | ||
| 49 | __alloc_size(2) | ||
| 50 | _FORTIFY_FN(realloc) void *realloc(void *__p, size_t __s) | ||
| 51 | { | ||
| 52 | return __orig_realloc(__p, __s); | ||
| 53 | } | ||
| 54 | |||
| 55 | __alloc_size(1, 2) | ||
| 56 | _FORTIFY_FN(calloc) void *calloc(size_t __n, size_t __s) | ||
| 57 | { | ||
| 58 | return __orig_calloc(__n, __s); | ||
| 59 | } | ||
| 60 | |||
| 61 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 62 | #undef reallocarray | ||
| 63 | __alloc_size (2, 3) | ||
| 64 | _FORTIFY_FN(reallocarray) void* reallocarray(void* __p, size_t __n, size_t __s) | ||
| 65 | { | ||
| 66 | return __orig_reallocarray(__p, __n, __s); | ||
| 67 | } | ||
| 68 | #endif | ||
| 69 | |||
| 47 | /* FIXME clang */ | 70 | /* FIXME clang */ |
| 48 | #if (defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) && !defined(__clang__) | 71 | #if (defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) && !defined(__clang__) |
| 49 | #undef realpath | 72 | #undef realpath |
