fortify-headers

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

commit 2ced6e28c30c98428a85a3c3fac7758d1ddf12b6
parent 7279c33202a77972301aa367667de9207f360c1b
Author: sin <sin@2f30.org>
Date:   Tue,  3 Mar 2015 14:34:35 +0000

Add fgetws() check

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

diff --git a/include/wchar.h b/include/wchar.h @@ -0,0 +1,24 @@ +#ifndef FORTIFY_WCHAR_H_ +#define FORTIFY_WCHAR_H_ + +#include_next <wchar.h> + +#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 + +static inline __attribute__ ((always_inline)) +wchar_t * +__fortify_fgetws(wchar_t *s, int n, FILE *fp) +{ + size_t bos = __builtin_object_size(s, 0); + + if ((size_t)n > bos / sizeof(wchar_t)) + __builtin_trap(); + return fgetws(s, n, fp); +} + +#undef fgetws +#define fgetws(s, n, fp) __fortify_fgetws(s, n, fp) + +#endif + +#endif