fortify-headers

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

commit f0efb87f8f5a0cc64b386ed6be4f9c2db328c37b
parent a810ecae686ae9133862a7ed4deabebc93d47b10
Author: sin <sin@2f30.org>
Date:   Tue,  3 Mar 2015 18:16:29 +0000

Add wmemcpy() and wmemmove() checks

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

diff --git a/include/wchar.h b/include/wchar.h @@ -18,6 +18,28 @@ __fortify_fgetws(wchar_t *s, int n, FILE *fp) static inline __attribute__ ((always_inline)) wchar_t * +__fortify_wmemcpy(wchar_t *d, const wchar_t *s, size_t n) +{ + size_t bos = __builtin_object_size(d, 0); + + if (n > bos / sizeof(wchar_t)) + __builtin_trap(); + return wmemcpy(d, s, n); +} + +static inline __attribute__ ((always_inline)) +wchar_t * +__fortify_wmemmove(wchar_t *d, const wchar_t *s, size_t n) +{ + size_t bos = __builtin_object_size(d, 0); + + if (n > bos / sizeof(wchar_t)) + __builtin_trap(); + return wmemmove(d, s, n); +} + +static inline __attribute__ ((always_inline)) +wchar_t * __fortify_wmemset(wchar_t *s, wchar_t c, size_t n) { size_t bos = __builtin_object_size(s, 0); @@ -29,6 +51,10 @@ __fortify_wmemset(wchar_t *s, wchar_t c, size_t n) #undef fgetws #define fgetws(s, n, fp) __fortify_fgetws(s, n, fp) +#undef wmemcpy +#define wmemcpy(d, s, n) __fortify_wmemcpy(d, s, n) +#undef wmemmove +#define wmemmove(d, s, n) __fortify_wmemmove(d, s, n) #undef wmemset #define wmemset(s, c, n) __fortify_wmemset(s, c, n)