fortify-headers

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

commit 3532ee2caade20142491a0e06a3ccd569a99131b
parent ce3377dbb20b5ff41349b195d2a3c21317012c98
Author: sin <sin@2f30.org>
Date:   Wed,  4 Mar 2015 12:59:41 +0000

Add wcsnrtombs() and wcsrtombs() checks

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

diff --git a/include/wchar.h b/include/wchar.h @@ -115,6 +115,30 @@ __fortify_wcsncpy(wchar_t *d, const wchar_t *s, size_t n) } static inline __attribute__ ((always_inline)) +size_t +__fortify_wcsnrtombs(char *d, const wchar_t **s, size_t wn, + size_t n, mbstate_t *st) +{ + size_t bos = __builtin_object_size(d, 0); + + if (n > bos) + __builtin_trap(); + return wcsnrtombs(d, s, wn, n, st); +} + +static inline __attribute__ ((always_inline)) +size_t +__fortify_wcsrtombs(char *d, const wchar_t **s, size_t n, + mbstate_t *st) +{ + size_t bos = __builtin_object_size(d, 0); + + if (n > bos) + __builtin_trap(); + return wcsrtombs(d, s, n, st); +} + +static inline __attribute__ ((always_inline)) wchar_t * __fortify_wmemcpy(wchar_t *d, const wchar_t *s, size_t n) { @@ -165,6 +189,10 @@ __fortify_wmemset(wchar_t *s, wchar_t c, size_t n) #define wcsncat(d, s, n) __fortify_wcsncat(d, s, n) #undef wcsncpy #define wcsncpy(d, s, n) __fortify_wcsncpy(d, s, n) +#undef wcsnrtombs +#define wcsnrtombs(d, s, wn, n, st) __fortify_wcsnrtombs(d, s, wn, n, st) +#undef wcsrtombs +#define wcsrtombs(d, s, n, st) __fortify_wcsrtombs(d, s, n, st) #undef wmemcpy #define wmemcpy(d, s, n) __fortify_wmemcpy(d, s, n) #undef wmemmove