fortify-headers

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

commit ead32d63209133fa83dbb43debd4db33b363d887
parent 9b128ed5384b9b474dee5a23d37047cd59e8646f
Author: sin <sin@2f30.org>
Date:   Fri Mar  6 12:39:11 +0000

Fix some checks in wchar.h

Some of these functions allow the destination pointer to be NULL.
Do not trap in that case as nothing will be written to the destination
buffer.

Diffstat:
include/wchar.h | 8++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/wchar.h b/include/wchar.h @@ -59,7 +59,7 @@ __fortify_mbstowcs(wchar_t *ws, const char *s, size_t wn) { size_t bos = __builtin_object_size(ws, 0); - if (wn > bos / sizeof(wchar_t)) + if (ws && wn > bos / sizeof(wchar_t)) __builtin_trap(); return mbstowcs(ws, s, wn); } @@ -70,7 +70,7 @@ __fortify_wcrtomb(char *s, wchar_t wc, mbstate_t *st) { size_t bos = __builtin_object_size(s, 0); - if (MB_CUR_MAX > bos) + if (s && MB_CUR_MAX > bos) __builtin_trap(); return wcrtomb(s, wc, st); } @@ -167,7 +167,7 @@ __fortify_wcstombs(char *s, const wchar_t *ws, size_t n) { size_t bos = __builtin_object_size(s, 0); - if (n > bos) + if (s && n > bos) __builtin_trap(); return wcstombs(s, ws, n); } @@ -178,7 +178,7 @@ __fortify_wctomb(char *s, wchar_t wc) { size_t bos = __builtin_object_size(s, 0); - if (MB_CUR_MAX > bos) + if (s && MB_CUR_MAX > bos) __builtin_trap(); return wctomb(s, wc); }