fortify-headers

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

commit 013d07a11c796651404a841db9179e3fda086b5f
parent 9626051b5d73fc6206010948f2f5f7fa51efb663
Author: sin <sin@2f30.org>
Date:   Wed Jan 28 16:21:38 +0000

Add stpncpy()

Diffstat:
include/string.h | 14++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)
diff --git a/include/string.h b/include/string.h @@ -54,6 +54,18 @@ char *__fortify_stpcpy(char *__restrict dest, const char *__restrict src) } static inline __attribute__ ((always_inline)) +char *__fortify_stpncpy(char *__restrict dest, const char *__restrict src, size_t n) +{ + size_t bos = __builtin_object_size(dest, 0); + + if (bos == (size_t)-1) + return stpcpy(dest, src); + if (__builtin_constant_p(n) && n > bos) + __builtin_trap(); + return stpncpy(dest, src, n); +} + +static inline __attribute__ ((always_inline)) char *__fortify_strcat(char *__restrict dest, const char *__restrict src) { size_t bos = __builtin_object_size(dest, 0); @@ -142,6 +154,8 @@ size_t __fortify_strlcpy(char *__restrict dest, const char *__restrict src, size #define memset(dest, src, n) __fortify_memset(dest, src, n) #undef stpcpy #define stpcpy(dest, src) __fortify_stpcpy(dest, src); +#undef stpncpy +#define stpncpy(dest, src, n) __fortify_stpncpy(dest, src, n); #undef strcat #define strcat(dest, src) __fortify_strcat(dest, src) #undef strcpy