diff options
Diffstat (limited to '')
| -rw-r--r-- | include/stdio.h | 10 | ||||
| -rw-r--r-- | include/stdlib.h | 5 | ||||
| -rw-r--r-- | include/string.h | 16 | ||||
| -rw-r--r-- | include/strings.h | 3 | ||||
| -rw-r--r-- | include/unistd.h | 2 | ||||
| -rw-r--r-- | include/wchar.h | 57 |
6 files changed, 44 insertions, 49 deletions
diff --git a/include/stdio.h b/include/stdio.h index 2d1ee33..468bf82 100644 --- a/include/stdio.h +++ b/include/stdio.h | |||
| @@ -37,7 +37,7 @@ extern "C" { | |||
| 37 | #undef snprintf | 37 | #undef snprintf |
| 38 | #undef sprintf | 38 | #undef sprintf |
| 39 | 39 | ||
| 40 | __fortify_access(read_write, 1, 2) | 40 | __fortify_access(write_only, 1, 2) |
| 41 | __fortify_access(read_only, 3) | 41 | __fortify_access(read_only, 3) |
| 42 | _FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f) | 42 | _FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f) |
| 43 | { | 43 | { |
| @@ -95,10 +95,10 @@ __fortify_access(read_only, 2) | |||
| 95 | _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f, | 95 | _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f, |
| 96 | __builtin_va_list __v) | 96 | __builtin_va_list __v) |
| 97 | { | 97 | { |
| 98 | size_t __b = __bos(__s, 0); | 98 | size_t __b = __bos(__s, 2); |
| 99 | int __r; | 99 | int __r; |
| 100 | 100 | ||
| 101 | if (__b != (size_t)-1) { | 101 | if (__b) { |
| 102 | __r = __orig_vsnprintf(__s, __b, __f, __v); | 102 | __r = __orig_vsnprintf(__s, __b, __f, __v); |
| 103 | if (__r != -1 && (size_t)__r >= __b) | 103 | if (__r != -1 && (size_t)__r >= __b) |
| 104 | __builtin_trap(); | 104 | __builtin_trap(); |
| @@ -136,10 +136,10 @@ _FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n, | |||
| 136 | __fortify__format(printf, 2, 3) | 136 | __fortify__format(printf, 2, 3) |
| 137 | _FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...) | 137 | _FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...) |
| 138 | { | 138 | { |
| 139 | size_t __b = __bos(__s, 0); | 139 | size_t __b = __bos(__s, 2); |
| 140 | int __r; | 140 | int __r; |
| 141 | 141 | ||
| 142 | if (__b != (size_t)-1) { | 142 | if (__b) { |
| 143 | __r = __orig_snprintf(__s, __b, __f, __builtin_va_arg_pack()); | 143 | __r = __orig_snprintf(__s, __b, __f, __builtin_va_arg_pack()); |
| 144 | if (__r != -1 && (size_t)__r >= __b) | 144 | if (__r != -1 && (size_t)__r >= __b) |
| 145 | __builtin_trap(); | 145 | __builtin_trap(); |
diff --git a/include/stdlib.h b/include/stdlib.h index c95bb55..bb10a7f 100644 --- a/include/stdlib.h +++ b/include/stdlib.h | |||
| @@ -45,6 +45,7 @@ _FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r) | |||
| 45 | #ifndef PATH_MAX | 45 | #ifndef PATH_MAX |
| 46 | /* see man realpath(3) */ | 46 | /* see man realpath(3) */ |
| 47 | #define PATH_MAX 4096 | 47 | #define PATH_MAX 4096 |
| 48 | #define _FORTIFY_UNDEF_PATH_MAX | ||
| 48 | #endif | 49 | #endif |
| 49 | if (__r && PATH_MAX > __bos(__r, 2)) { | 50 | if (__r && PATH_MAX > __bos(__r, 2)) { |
| 50 | char __buf[PATH_MAX], *__ret; | 51 | char __buf[PATH_MAX], *__ret; |
| @@ -61,6 +62,10 @@ _FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r) | |||
| 61 | } | 62 | } |
| 62 | return __orig_realpath(__p, __r); | 63 | return __orig_realpath(__p, __r); |
| 63 | } | 64 | } |
| 65 | #ifdef _FORTIFY_UNDEF_PATH_MAX | ||
| 66 | #undef PATH_MAX | ||
| 67 | #undef _FORTIFY_UNDEF_PATH_MAX | ||
| 68 | #endif | ||
| 64 | #endif | 69 | #endif |
| 65 | 70 | ||
| 66 | #ifdef __cplusplus | 71 | #ifdef __cplusplus |
diff --git a/include/string.h b/include/string.h index 7987d17..44206f0 100644 --- a/include/string.h +++ b/include/string.h | |||
| @@ -104,7 +104,7 @@ _FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s, | |||
| 104 | { | 104 | { |
| 105 | size_t __b = __bos(__d, 0); | 105 | size_t __b = __bos(__d, 0); |
| 106 | 106 | ||
| 107 | if (__n > __b && strlen(__s) + 1 > __b) | 107 | if (__n > __b) |
| 108 | __builtin_trap(); | 108 | __builtin_trap(); |
| 109 | return __orig_stpncpy(__d, __s, __n); | 109 | return __orig_stpncpy(__d, __s, __n); |
| 110 | } | 110 | } |
| @@ -140,14 +140,12 @@ _FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s, | |||
| 140 | size_t __b = __bos(__d, 0); | 140 | size_t __b = __bos(__d, 0); |
| 141 | size_t __sl, __dl; | 141 | size_t __sl, __dl; |
| 142 | 142 | ||
| 143 | if (__n > __b) { | 143 | __sl = strlen(__s); |
| 144 | __sl = strlen(__s); | 144 | __dl = strlen(__d); |
| 145 | __dl = strlen(__d); | 145 | if (__sl > __n) |
| 146 | if (__sl > __n) | 146 | __sl = __n; |
| 147 | __sl = __n; | 147 | if (__sl + __dl + 1 > __b) |
| 148 | if (__sl + __dl + 1 > __b) | 148 | __builtin_trap(); |
| 149 | __builtin_trap(); | ||
| 150 | } | ||
| 151 | return __orig_strncat(__d, __s, __n); | 149 | return __orig_strncat(__d, __s, __n); |
| 152 | } | 150 | } |
| 153 | 151 | ||
diff --git a/include/strings.h b/include/strings.h index 6a17ca3..5147936 100644 --- a/include/strings.h +++ b/include/strings.h | |||
| @@ -17,6 +17,9 @@ | |||
| 17 | #ifndef _FORTIFY_STRINGS_H | 17 | #ifndef _FORTIFY_STRINGS_H |
| 18 | #define _FORTIFY_STRINGS_H | 18 | #define _FORTIFY_STRINGS_H |
| 19 | 19 | ||
| 20 | #if !defined(__cplusplus) && !defined(__clang__) | ||
| 21 | __extension__ | ||
| 22 | #endif | ||
| 20 | #include_next <strings.h> | 23 | #include_next <strings.h> |
| 21 | 24 | ||
| 22 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 | 25 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 |
diff --git a/include/unistd.h b/include/unistd.h index a2b3105..a73279b 100644 --- a/include/unistd.h +++ b/include/unistd.h | |||
| @@ -177,7 +177,7 @@ _FORTIFY_FN(swab) void swab(const void * _FORTIFY_POS0 __os, | |||
| 177 | size_t __bs = __bos(__os, 0); | 177 | size_t __bs = __bos(__os, 0); |
| 178 | size_t __bd = __bos(__od, 0); | 178 | size_t __bd = __bos(__od, 0); |
| 179 | 179 | ||
| 180 | if ((size_t)__n > __bs || (size_t)__n > __bd) | 180 | if (__n > 0 && ((size_t)__n > __bs || (size_t)__n > __bd)) |
| 181 | __builtin_trap(); | 181 | __builtin_trap(); |
| 182 | return __orig_swab(__os, __od, __n); | 182 | return __orig_swab(__os, __od, __n); |
| 183 | } | 183 | } |
diff --git a/include/wchar.h b/include/wchar.h index a840f1a..4346023 100644 --- a/include/wchar.h +++ b/include/wchar.h | |||
| @@ -75,16 +75,10 @@ _FORTIFY_FN(mbsnrtowcs) size_t mbsnrtowcs(wchar_t * _FORTIFY_POS0 __d, | |||
| 75 | size_t __b = __bos(__d, 0); | 75 | size_t __b = __bos(__d, 0); |
| 76 | size_t __r; | 76 | size_t __r; |
| 77 | 77 | ||
| 78 | if (__wn > __n / sizeof(wchar_t)) { | 78 | __b /= sizeof(wchar_t); |
| 79 | __b /= sizeof(wchar_t); | 79 | __r = __orig_mbsnrtowcs(__d, __s, __n, __wn > __b ? __b : __wn, __st); |
| 80 | __r = __orig_mbsnrtowcs(__d, __s, __n, __wn > __b ? __b : __wn, __st); | 80 | if (__b < __wn && __d && *__s && __r != (size_t)-1) |
| 81 | if (__b < __wn && __d && *__s && __r != (size_t)-1) | 81 | __builtin_trap(); |
| 82 | __builtin_trap(); | ||
| 83 | } else { | ||
| 84 | __r = __orig_mbsnrtowcs(__d, __s, __n > __b ? __b : __n, __wn, __st); | ||
| 85 | if (__b < __n && __d && *__s && __r != (size_t)-1) | ||
| 86 | __builtin_trap(); | ||
| 87 | } | ||
| 88 | return __r; | 82 | return __r; |
| 89 | } | 83 | } |
| 90 | #endif | 84 | #endif |
| @@ -159,14 +153,12 @@ _FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t * _FORTIFY_POS0 __d, | |||
| 159 | size_t __b = __bos(__d, 0); | 153 | size_t __b = __bos(__d, 0); |
| 160 | size_t __sl, __dl; | 154 | size_t __sl, __dl; |
| 161 | 155 | ||
| 162 | if (__n > __b / sizeof(wchar_t)) { | 156 | __sl = wcslen(__s); |
| 163 | __sl = wcslen(__s); | 157 | __dl = wcslen(__d); |
| 164 | __dl = wcslen(__d); | 158 | if (__sl > __n) |
| 165 | if (__sl > __n) | 159 | __sl = __n; |
| 166 | __sl = __n; | 160 | if (__sl + __dl + 1 > __b / sizeof(wchar_t)) |
| 167 | if (__sl + __dl + 1 > __b / sizeof(wchar_t)) | 161 | __builtin_trap(); |
| 168 | __builtin_trap(); | ||
| 169 | } | ||
| 170 | return __orig_wcsncat(__d, __s, __n); | 162 | return __orig_wcsncat(__d, __s, __n); |
| 171 | } | 163 | } |
| 172 | 164 | ||
| @@ -190,16 +182,9 @@ _FORTIFY_FN(wcsnrtombs) size_t wcsnrtombs(char * _FORTIFY_POS0 __d, | |||
| 190 | size_t __b = __bos(__d, 0); | 182 | size_t __b = __bos(__d, 0); |
| 191 | size_t __r; | 183 | size_t __r; |
| 192 | 184 | ||
| 193 | if (__wn > __n / sizeof(wchar_t)) { | 185 | __r = __orig_wcsnrtombs(__d, __s, __wn, __n > __b ? __b : __n, __st); |
| 194 | __b /= sizeof(wchar_t); | 186 | if (__b < __n && __d && *__s && __r != (size_t)-1) |
| 195 | __r = __orig_wcsnrtombs(__d, __s, __wn > __b ? __b : __wn, __n, __st); | 187 | __builtin_trap(); |
| 196 | if (__b < __wn && __d && *__s && __r != (size_t)-1) | ||
| 197 | __builtin_trap(); | ||
| 198 | } else { | ||
| 199 | __r = __orig_wcsnrtombs(__d, __s, __wn, __n > __b ? __b : __n, __st); | ||
| 200 | if (__b < __n && __d && *__s && __r != (size_t)-1) | ||
| 201 | __builtin_trap(); | ||
| 202 | } | ||
| 203 | return __r; | 188 | return __r; |
| 204 | } | 189 | } |
| 205 | #endif | 190 | #endif |
| @@ -228,21 +213,25 @@ _FORTIFY_FN(wcstombs) size_t wcstombs(char * _FORTIFY_POS0 __s, | |||
| 228 | } | 213 | } |
| 229 | 214 | ||
| 230 | _FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t * _FORTIFY_POS0 __d, | 215 | _FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t * _FORTIFY_POS0 __d, |
| 231 | const wchar_t *__s, size_t __n) | 216 | const wchar_t * _FORTIFY_POS0 __s, |
| 217 | size_t __n) | ||
| 232 | { | 218 | { |
| 233 | size_t __b = __bos(__d, 0); | 219 | size_t __bd = __bos(__d, 0); |
| 220 | size_t __bs = __bos(__s, 0); | ||
| 234 | 221 | ||
| 235 | if (__n > __b / sizeof(wchar_t)) | 222 | if (__n > __bd / sizeof(wchar_t) || __n > __bs / sizeof(wchar_t)) |
| 236 | __builtin_trap(); | 223 | __builtin_trap(); |
| 237 | return __orig_wmemcpy(__d, __s, __n); | 224 | return __orig_wmemcpy(__d, __s, __n); |
| 238 | } | 225 | } |
| 239 | 226 | ||
| 240 | _FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t * _FORTIFY_POS0 __d, | 227 | _FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t * _FORTIFY_POS0 __d, |
| 241 | const wchar_t *__s, size_t __n) | 228 | const wchar_t * _FORTIFY_POS0 __s, |
| 229 | size_t __n) | ||
| 242 | { | 230 | { |
| 243 | size_t __b = __bos(__d, 0); | 231 | size_t __bd = __bos(__d, 0); |
| 232 | size_t __bs = __bos(__s, 0); | ||
| 244 | 233 | ||
| 245 | if (__n > __b / sizeof(wchar_t)) | 234 | if (__n > __bd / sizeof(wchar_t) || __n > __bs / sizeof(wchar_t)) |
| 246 | __builtin_trap(); | 235 | __builtin_trap(); |
| 247 | return __orig_wmemmove(__d, __s, __n); | 236 | return __orig_wmemmove(__d, __s, __n); |
| 248 | } | 237 | } |
