fortify-headers

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

commit 9626051b5d73fc6206010948f2f5f7fa51efb663
parent de7999ee82b87ef262d0601a40169775b8e94285
Author: sin <sin@2f30.org>
Date:   Wed, 28 Jan 2015 16:16:23 +0000

Add stpcpy()

Diffstat:
Minclude/string.h | 14++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)

diff --git a/include/string.h b/include/string.h @@ -42,6 +42,18 @@ void *__fortify_memset(void *dest, int c, size_t n) } static inline __attribute__ ((always_inline)) +char *__fortify_stpcpy(char *__restrict dest, const char *__restrict src) +{ + size_t bos = __builtin_object_size(dest, 0); + + if (bos == (size_t)-1) + return stpcpy(dest, src); + if (strlen(src) + 1 > bos) + __builtin_trap(); + return stpcpy(dest, src); +} + +static inline __attribute__ ((always_inline)) char *__fortify_strcat(char *__restrict dest, const char *__restrict src) { size_t bos = __builtin_object_size(dest, 0); @@ -128,6 +140,8 @@ size_t __fortify_strlcpy(char *__restrict dest, const char *__restrict src, size #define memmove(dest, src, n) __fortify_memmove(dest, src, n) #undef memset #define memset(dest, src, n) __fortify_memset(dest, src, n) +#undef stpcpy +#define stpcpy(dest, src) __fortify_stpcpy(dest, src); #undef strcat #define strcat(dest, src) __fortify_strcat(dest, src) #undef strcpy