fortify-headers

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

commit 4ddbe16d881bb8ea70f63ea55f92fa5bb4c7802d
parent 7392bcaef8dfdfba67253f3b84f1f1a611e7bab3
Author: sin <sin@2f30.org>
Date:   Wed,  4 Mar 2015 18:26:59 +0000

Fix mbsrtowcs() check

Diffstat:
Minclude/wchar.h | 7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/wchar.h b/include/wchar.h @@ -41,10 +41,13 @@ __fortify_mbsrtowcs(wchar_t *d, const char **s, size_t wn, mbstate_t *st) { size_t bos = __builtin_object_size(d, 0); + size_t r; - if (wn > bos / sizeof(wchar_t)) + bos /= sizeof(wchar_t); + r = mbsrtowcs(d, s, wn > bos ? bos : wn, st); + if (bos < wn && d && *s && r != (size_t)-1) __builtin_trap(); - return mbsrtowcs(d, s, wn, st); + return r; } static inline __attribute__ ((always_inline))