diff options
| author | sin | 2015-03-04 13:09:31 +0000 |
|---|---|---|
| committer | sin | 2015-03-04 13:09:31 +0000 |
| commit | 911f402e9479c16a567adcf36711517732683f3d (patch) | |
| tree | bb1c9a82b27a57edb7af5775890eed8e11eb95ce /include/wchar.h | |
| parent | 3532ee2caade20142491a0e06a3ccd569a99131b (diff) | |
Add wcstombs() check
Diffstat (limited to 'include/wchar.h')
| -rw-r--r-- | include/wchar.h | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/include/wchar.h b/include/wchar.h index a482371..07ab119 100644 --- a/include/wchar.h +++ b/include/wchar.h | |||
| @@ -43,13 +43,13 @@ __fortify_mbsrtowcs(wchar_t *d, const char **s, | |||
| 43 | 43 | ||
| 44 | static inline __attribute__ ((always_inline)) | 44 | static inline __attribute__ ((always_inline)) |
| 45 | size_t | 45 | size_t |
| 46 | __fortify_mbstowcs(wchar_t *d, const char *s, size_t n) | 46 | __fortify_mbstowcs(wchar_t *ws, const char *s, size_t wn) |
| 47 | { | 47 | { |
| 48 | size_t bos = __builtin_object_size(d, 0); | 48 | size_t bos = __builtin_object_size(ws, 0); |
| 49 | 49 | ||
| 50 | if (n > bos / sizeof(wchar_t)) | 50 | if (wn > bos / sizeof(wchar_t)) |
| 51 | __builtin_trap(); | 51 | __builtin_trap(); |
| 52 | return mbstowcs(d, s, n); | 52 | return mbstowcs(ws, s, wn); |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | static inline __attribute__ ((always_inline)) | 55 | static inline __attribute__ ((always_inline)) |
| @@ -139,6 +139,17 @@ __fortify_wcsrtombs(char *d, const wchar_t **s, size_t n, | |||
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | static inline __attribute__ ((always_inline)) | 141 | static inline __attribute__ ((always_inline)) |
| 142 | size_t | ||
| 143 | __fortify_wcstombs(char *s, const wchar_t *ws, size_t n) | ||
| 144 | { | ||
| 145 | size_t bos = __builtin_object_size(s, 0); | ||
| 146 | |||
| 147 | if (n > bos) | ||
| 148 | __builtin_trap(); | ||
| 149 | return wcstombs(s, ws, n); | ||
| 150 | } | ||
| 151 | |||
| 152 | static inline __attribute__ ((always_inline)) | ||
| 142 | wchar_t * | 153 | wchar_t * |
| 143 | __fortify_wmemcpy(wchar_t *d, const wchar_t *s, size_t n) | 154 | __fortify_wmemcpy(wchar_t *d, const wchar_t *s, size_t n) |
| 144 | { | 155 | { |
| @@ -178,7 +189,7 @@ __fortify_wmemset(wchar_t *s, wchar_t c, size_t n) | |||
| 178 | #undef mbsrtowcs | 189 | #undef mbsrtowcs |
| 179 | #define mbsrtowcs(d, s, wn, st) __fortify_mbsrtowcs(d, s, wn, st) | 190 | #define mbsrtowcs(d, s, wn, st) __fortify_mbsrtowcs(d, s, wn, st) |
| 180 | #undef mbstowcs | 191 | #undef mbstowcs |
| 181 | #define mbstowcs(d, s, n) __fortify_mbstowcs(d, s, n) | 192 | #define mbstowcs(ws, s, wn) __fortify_mbstowcs(ws, s, wn) |
| 182 | #undef wcrtomb | 193 | #undef wcrtomb |
| 183 | #define wcrtomb(s, wc, st) __fortify_wcrtomb(s, wc, st) | 194 | #define wcrtomb(s, wc, st) __fortify_wcrtomb(s, wc, st) |
| 184 | #undef wcscat | 195 | #undef wcscat |
| @@ -193,6 +204,8 @@ __fortify_wmemset(wchar_t *s, wchar_t c, size_t n) | |||
| 193 | #define wcsnrtombs(d, s, wn, n, st) __fortify_wcsnrtombs(d, s, wn, n, st) | 204 | #define wcsnrtombs(d, s, wn, n, st) __fortify_wcsnrtombs(d, s, wn, n, st) |
| 194 | #undef wcsrtombs | 205 | #undef wcsrtombs |
| 195 | #define wcsrtombs(d, s, n, st) __fortify_wcsrtombs(d, s, n, st) | 206 | #define wcsrtombs(d, s, n, st) __fortify_wcsrtombs(d, s, n, st) |
| 207 | #undef wcstombs | ||
| 208 | #define wcstombs(s, ws, n) __fortify_wcstombs(s, ws, n) | ||
| 196 | #undef wmemcpy | 209 | #undef wmemcpy |
| 197 | #define wmemcpy(d, s, n) __fortify_wmemcpy(d, s, n) | 210 | #define wmemcpy(d, s, n) __fortify_wmemcpy(d, s, n) |
| 198 | #undef wmemmove | 211 | #undef wmemmove |
