fortify-headers

standalone fortify-source implementation
git clone git://git.2f30.org/fortify-headers.git
Log | Files | Refs | README | LICENSE

commit c49f6215ea82e87bd6783664a1f7946cebc9344e
parent 31f2952bc70bc521e3392a9465a306dbb1dd1b38
Author: sin <sin@2f30.org>
Date:   Wed Jan 28 17:44:38 +0000

Add mempcpy() checks

Diffstat:
include/string.h | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)
diff --git a/include/string.h b/include/string.h @@ -102,6 +102,18 @@ char *__fortify_strncpy(char *__restrict dest, const char *__restrict src, size_ return strncpy(dest, src, n); } +#if defined(_GNU_SOURCE) +static inline __attribute__ ((always_inline)) +void *__fortify_mempcpy(void *__restrict dest, const void *__restrict src, size_t n) +{ + size_t bos = __builtin_object_size(dest, 0); + + if (n > bos) + __builtin_trap(); + return mempcpy(dest, src, n); +} +#endif + #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) static inline __attribute__ ((always_inline)) size_t __fortify_strlcat(char *__restrict dest, const char *__restrict src, size_t n) @@ -143,6 +155,11 @@ size_t __fortify_strlcpy(char *__restrict dest, const char *__restrict src, size #undef strncpy #define strncpy(dest, src, n) __fortify_strcpy(dest, src, n) +#if defined(_GNU_SOURCE) +#undef mempcpy +#define mempcpy(dest, src, n) __fortify_mempcpy(dest, src, n) +#endif + #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #undef strlcat #define strlcat(dest, src, n) __fortify_strlcat(dest, src, n)