diff options
| author | jvoisin | 2023-09-27 23:23:13 +0200 |
|---|---|---|
| committer | jvoisin | 2023-09-27 23:23:13 +0200 |
| commit | 81ef1fd8c55aae65d321b2730ff5da6b73d1e707 (patch) | |
| tree | f6dcafc6063c7dbaacb9a71f54c9ff171a17d5b4 /include | |
| parent | 2ccfced2116d00e6ddf3aa6f10cfacab5a863c76 (diff) | |
Add support for more builtin compiler provided _chk variants
Diffstat (limited to 'include')
| -rw-r--r-- | include/stdio.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/include/stdio.h b/include/stdio.h index 25e7ad2..b407d0f 100644 --- a/include/stdio.h +++ b/include/stdio.h | |||
| @@ -165,7 +165,7 @@ __diagnose_as_builtin(__builtin_vsprintf, 1, 2, 3) | |||
| 165 | _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f, | 165 | _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f, |
| 166 | __builtin_va_list __v) | 166 | __builtin_va_list __v) |
| 167 | { | 167 | { |
| 168 | #if __has_builtin(__builtin___vsnprintf_chk) && USE_NATIVE_CHK | 168 | #if __has_builtin(__builtin___vsprintf_chk) && USE_NATIVE_CHK |
| 169 | return __builtin___vsprintf_chk(__s, _FORTIFY_SOURCE, __bos(__s, 0), __f, __v,); | 169 | return __builtin___vsprintf_chk(__s, _FORTIFY_SOURCE, __bos(__s, 0), __f, __v,); |
| 170 | #else | 170 | #else |
| 171 | size_t __b = __bos(__s, 0); | 171 | size_t __b = __bos(__s, 0); |
| @@ -208,11 +208,15 @@ __format(printf, 3, 4) | |||
| 208 | _FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n, | 208 | _FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n, |
| 209 | const char *__f, ...) | 209 | const char *__f, ...) |
| 210 | { | 210 | { |
| 211 | #if __has_builtin(__builtin___snprintf_chk) && USE_NATIVE_CHK | ||
| 212 | return __builtin___snprintf_chk(__s, __n, _FORTIFY_SOURCE, __bos(__s, 0), __f, __builtin_va_arg_pack()); | ||
| 213 | #else | ||
| 211 | size_t __b = __bos(__s, 0); | 214 | size_t __b = __bos(__s, 0); |
| 212 | 215 | ||
| 213 | if (__n > __b) | 216 | if (__n > __b) |
| 214 | __builtin_trap(); | 217 | __builtin_trap(); |
| 215 | return __orig_snprintf(__s, __n, __f, __builtin_va_arg_pack()); | 218 | return __orig_snprintf(__s, __n, __f, __builtin_va_arg_pack()); |
| 219 | #endif | ||
| 216 | } | 220 | } |
| 217 | 221 | ||
| 218 | __format(printf, 2, 3) | 222 | __format(printf, 2, 3) |
| @@ -220,6 +224,9 @@ __access(read_write, 1) | |||
| 220 | __access(read_only, 2) | 224 | __access(read_only, 2) |
| 221 | _FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...) | 225 | _FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...) |
| 222 | { | 226 | { |
| 227 | #if __has_builtin(__builtin___sprintf_chk) && USE_NATIVE_CHK | ||
| 228 | return __builtin___sprintf_chk(__s, _FORTIFY_SOURCE, __bos(__s, 0), __f, __builtin_va_arg_pack()); | ||
| 229 | #else | ||
| 223 | size_t __b = __bos(__s, 0); | 230 | size_t __b = __bos(__s, 0); |
| 224 | int __r; | 231 | int __r; |
| 225 | 232 | ||
| @@ -231,6 +238,7 @@ _FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...) | |||
| 231 | __r = __orig_sprintf(__s, __f, __builtin_va_arg_pack()); | 238 | __r = __orig_sprintf(__s, __f, __builtin_va_arg_pack()); |
| 232 | } | 239 | } |
| 233 | return __r; | 240 | return __r; |
| 241 | #endif | ||
| 234 | } | 242 | } |
| 235 | 243 | ||
| 236 | #endif /* __has_builtin(__builtin_va_arg_pack) */ | 244 | #endif /* __has_builtin(__builtin_va_arg_pack) */ |
