From f0efb87f8f5a0cc64b386ed6be4f9c2db328c37b Mon Sep 17 00:00:00 2001 From: sin Date: Tue, 3 Mar 2015 18:16:29 +0000 Subject: [PATCH] Add wmemcpy() and wmemmove() checks --- include/wchar.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/wchar.h b/include/wchar.h index 54df2be..9360eb5 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -16,6 +16,28 @@ __fortify_fgetws(wchar_t *s, int n, FILE *fp) return fgetws(s, n, 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) @@ -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)