fortify-headers

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

commit 3d237352de2832b07b2f61349cf618f5880a1e7b
parent 911f402e9479c16a567adcf36711517732683f3d
Author: sin <sin@2f30.org>
Date:   Wed Mar  4 13:12:58 +0000

Add wctomb() check

Diffstat:
include/wchar.h | 13+++++++++++++
1 file changed, 13 insertions(+), 0 deletions(-)
diff --git a/include/wchar.h b/include/wchar.h @@ -150,6 +150,17 @@ __fortify_wcstombs(char *s, const wchar_t *ws, size_t n) } static inline __attribute__ ((always_inline)) +int +__fortify_wctomb(char *s, wchar_t wc) +{ + size_t bos = __builtin_object_size(s, 0); + + if (MB_CUR_MAX > bos) + __builtin_trap(); + return wctomb(s, wc); +} + +static inline __attribute__ ((always_inline)) wchar_t * __fortify_wmemcpy(wchar_t *d, const wchar_t *s, size_t n) { @@ -206,6 +217,8 @@ __fortify_wmemset(wchar_t *s, wchar_t c, size_t n) #define wcsrtombs(d, s, n, st) __fortify_wcsrtombs(d, s, n, st) #undef wcstombs #define wcstombs(s, ws, n) __fortify_wcstombs(s, ws, n) +#undef wctomb +#define wctomb(s, wc) __fortify_wctomb(s, wc) #undef wmemcpy #define wmemcpy(d, s, n) __fortify_wmemcpy(d, s, n) #undef wmemmove