diff options
| -rw-r--r-- | include/stdio.h | 21 | ||||
| -rw-r--r-- | tests/Makefile | 1 |
2 files changed, 19 insertions, 3 deletions
diff --git a/include/stdio.h b/include/stdio.h index 9415f83..3bbee38 100644 --- a/include/stdio.h +++ b/include/stdio.h | |||
| @@ -36,8 +36,6 @@ extern "C" { | |||
| 36 | #undef fread | 36 | #undef fread |
| 37 | #undef fwrite | 37 | #undef fwrite |
| 38 | #undef popen | 38 | #undef popen |
| 39 | #undef printf | ||
| 40 | #undef vprintf | ||
| 41 | #undef vsnprintf | 39 | #undef vsnprintf |
| 42 | #undef vsprintf | 40 | #undef vsprintf |
| 43 | 41 | ||
| @@ -185,6 +183,7 @@ _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f, | |||
| 185 | } | 183 | } |
| 186 | 184 | ||
| 187 | #ifndef __clang__ /* FIXME */ | 185 | #ifndef __clang__ /* FIXME */ |
| 186 | #undef vprintf | ||
| 188 | __access(read_only, 1) | 187 | __access(read_only, 1) |
| 189 | __format(printf, 1, 0) | 188 | __format(printf, 1, 0) |
| 190 | #if __has_builtin(__builtin_vprintf) | 189 | #if __has_builtin(__builtin_vprintf) |
| @@ -198,7 +197,7 @@ _FORTIFY_FN(vprintf) int vprintf(const char *__f, __builtin_va_list __v) | |||
| 198 | return __orig_vprintf(__f, __v); | 197 | return __orig_vprintf(__f, __v); |
| 199 | #endif | 198 | #endif |
| 200 | } | 199 | } |
| 201 | #endif | 200 | #endif // __clang__ |
| 202 | 201 | ||
| 203 | 202 | ||
| 204 | #if __has_builtin(__builtin_va_arg_pack) | 203 | #if __has_builtin(__builtin_va_arg_pack) |
| @@ -219,6 +218,8 @@ _FORTIFY_FN(vprintf) int vprintf(const char *__f, __builtin_va_list __v) | |||
| 219 | 218 | ||
| 220 | #undef snprintf | 219 | #undef snprintf |
| 221 | #undef sprintf | 220 | #undef sprintf |
| 221 | #undef printf | ||
| 222 | #undef fprintf | ||
| 222 | 223 | ||
| 223 | __access(read_write, 1, 2) | 224 | __access(read_write, 1, 2) |
| 224 | __access(read_only, 3) | 225 | __access(read_only, 3) |
| @@ -270,6 +271,20 @@ _FORTIFY_FN(printf) int printf(const char *__f, ...) | |||
| 270 | #endif | 271 | #endif |
| 271 | } | 272 | } |
| 272 | 273 | ||
| 274 | __access(read_only, 2) | ||
| 275 | __format(printf, 2, 0) | ||
| 276 | #if __has_builtin(__builtin_fprintf) | ||
| 277 | __diagnose_as_builtin(__builtin_fprintf, 2, 3) | ||
| 278 | #endif | ||
| 279 | _FORTIFY_FN(fprintf) int fprintf(FILE *__s, const char *__f, ...) | ||
| 280 | { | ||
| 281 | #if __has_builtin(__builtin___fprintf_chk) && USE_NATIVE_CHK | ||
| 282 | return __builtin___fprintf_chk(_FORTIFY_SOURCE, __s, __f, __builtin_va_arg_pack()); | ||
| 283 | #else | ||
| 284 | return __orig_fprintf(__s, __f, __builtin_va_arg_pack()); | ||
| 285 | #endif | ||
| 286 | } | ||
| 287 | |||
| 273 | #endif /* __has_builtin(__builtin_va_arg_pack) */ | 288 | #endif /* __has_builtin(__builtin_va_arg_pack) */ |
| 274 | 289 | ||
| 275 | #ifdef __cplusplus | 290 | #ifdef __cplusplus |
diff --git a/tests/Makefile b/tests/Makefile index 4c127b5..445ac9c 100644 --- a/tests/Makefile +++ b/tests/Makefile | |||
| @@ -22,6 +22,7 @@ RUNTIME_TARGETS= \ | |||
| 22 | test_fgets_static \ | 22 | test_fgets_static \ |
| 23 | test_fgetws_dynamic \ | 23 | test_fgetws_dynamic \ |
| 24 | test_fgetws_static \ | 24 | test_fgetws_static \ |
| 25 | test_fprintf \ | ||
| 25 | test_fread_int_overflow \ | 26 | test_fread_int_overflow \ |
| 26 | test_fread_overwrite_dynamic \ | 27 | test_fread_overwrite_dynamic \ |
| 27 | test_fread_overwrite_static \ | 28 | test_fread_overwrite_static \ |
