diff options
| author | q66 | 2023-12-15 23:05:29 +0100 |
|---|---|---|
| committer | Julien Voisin | 2023-12-15 23:32:23 +0100 |
| commit | 8d090c8a1a86408fa8b54029b97fccd17f9d35d5 (patch) | |
| tree | 941e3cfb70300f8ecd5e79c21f7a5389e3ab87fc /include | |
| parent | c607773a80e6685ab4c922245c33cf2ea5dcfb72 (diff) | |
Guard some conditional stdio APIs with the right macros
Fixes https://github.com/jvoisin/fortify-headers/issues/34
Diffstat (limited to 'include')
| -rw-r--r-- | include/stdio.h | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/include/stdio.h b/include/stdio.h index 0e06e83..59ae4ff 100644 --- a/include/stdio.h +++ b/include/stdio.h | |||
| @@ -29,16 +29,21 @@ __extension__ | |||
| 29 | extern "C" { | 29 | extern "C" { |
| 30 | #endif | 30 | #endif |
| 31 | 31 | ||
| 32 | #undef fdopen | ||
| 33 | #undef fgets | 32 | #undef fgets |
| 34 | #undef fmemopen | ||
| 35 | #undef fopen | 33 | #undef fopen |
| 36 | #undef fread | 34 | #undef fread |
| 37 | #undef fwrite | 35 | #undef fwrite |
| 38 | #undef popen | ||
| 39 | #undef vsnprintf | 36 | #undef vsnprintf |
| 40 | #undef vsprintf | 37 | #undef vsprintf |
| 41 | 38 | ||
| 39 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 40 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 41 | || defined(_BSD_SOURCE) | ||
| 42 | |||
| 43 | #undef fdopen | ||
| 44 | #undef fmemopen | ||
| 45 | #undef popen | ||
| 46 | |||
| 42 | __access(read_only, 2) | 47 | __access(read_only, 2) |
| 43 | #if __has_builtin(__builtin_fdopen) | 48 | #if __has_builtin(__builtin_fdopen) |
| 44 | __diagnose_as_builtin(__builtin_fdopen, 1, 2) | 49 | __diagnose_as_builtin(__builtin_fdopen, 1, 2) |
| @@ -48,6 +53,28 @@ _FORTIFY_FN(fdopen) FILE *fdopen(int __f, const char* _FORTIFY_POS0 __m) | |||
| 48 | return __orig_fdopen(__f, __m); | 53 | return __orig_fdopen(__f, __m); |
| 49 | } | 54 | } |
| 50 | 55 | ||
| 56 | __malloc(malloc (fclose, 1)) | ||
| 57 | #if __has_builtin(__builtin_fmemopen) | ||
| 58 | __diagnose_as_builtin(__builtin_fmemopen, 1, 2, 3) | ||
| 59 | #endif | ||
| 60 | _FORTIFY_FN(fmemopen) FILE *fmemopen(void* _FORTIFY_POS0 __b, size_t __s, const char* _FORTIFY_POS0 __m) | ||
| 61 | { | ||
| 62 | return __orig_fmemopen(__b, __s, __m); | ||
| 63 | } | ||
| 64 | |||
| 65 | __access(read_only, 1) | ||
| 66 | __access(read_only, 2) | ||
| 67 | __malloc(malloc (pclose, 1)) | ||
| 68 | #if __has_builtin(__builtin_popen) | ||
| 69 | __diagnose_as_builtin(__builtin_popen, 1, 2) | ||
| 70 | #endif | ||
| 71 | _FORTIFY_FN(popen) FILE *popen(const char* _FORTIFY_POS0 __c, const char* _FORTIFY_POS0 __t) | ||
| 72 | { | ||
| 73 | return __orig_popen(__c, __t); | ||
| 74 | } | ||
| 75 | |||
| 76 | #endif /* _POSIX_SOURCE || _POSIX_C_SOURCE || _XOPEN_SOURCE || _GNU_SOURCE || _BSD_SOURCE */ | ||
| 77 | |||
| 51 | __access(write_only, 1, 2) | 78 | __access(write_only, 1, 2) |
| 52 | #if __has_builtin(__builtin_fgets) | 79 | #if __has_builtin(__builtin_fgets) |
| 53 | __diagnose_as_builtin(__builtin_fgets, 1, 2, 3) | 80 | __diagnose_as_builtin(__builtin_fgets, 1, 2, 3) |
| @@ -61,15 +88,6 @@ _FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f) | |||
| 61 | return __orig_fgets(__s, __n, __f); | 88 | return __orig_fgets(__s, __n, __f); |
| 62 | } | 89 | } |
| 63 | 90 | ||
| 64 | __malloc(malloc (fclose, 1)) | ||
| 65 | #if __has_builtin(__builtin_fmemopen) | ||
| 66 | __diagnose_as_builtin(__builtin_fmemopen, 1, 2, 3) | ||
| 67 | #endif | ||
| 68 | _FORTIFY_FN(fmemopen) FILE *fmemopen(void* _FORTIFY_POS0 __b, size_t __s, const char* _FORTIFY_POS0 __m) | ||
| 69 | { | ||
| 70 | return __orig_fmemopen(__b, __s, __m); | ||
| 71 | } | ||
| 72 | |||
| 73 | __access(read_only, 1) | 91 | __access(read_only, 1) |
| 74 | __access(read_only, 2) | 92 | __access(read_only, 2) |
| 75 | __malloc(malloc (fclose, 1)) | 93 | __malloc(malloc (fclose, 1)) |
| @@ -113,17 +131,6 @@ _FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n, | |||
| 113 | return __orig_fwrite(__d, __n, __m, __f); | 131 | return __orig_fwrite(__d, __n, __m, __f); |
| 114 | } | 132 | } |
| 115 | 133 | ||
| 116 | __access(read_only, 1) | ||
| 117 | __access(read_only, 2) | ||
| 118 | __malloc(malloc (pclose, 1)) | ||
| 119 | #if __has_builtin(__builtin_popen) | ||
| 120 | __diagnose_as_builtin(__builtin_popen, 1, 2) | ||
| 121 | #endif | ||
| 122 | _FORTIFY_FN(popen) FILE *popen(const char* _FORTIFY_POS0 __c, const char* _FORTIFY_POS0 __t) | ||
| 123 | { | ||
| 124 | return __orig_popen(__c, __t); | ||
| 125 | } | ||
| 126 | |||
| 127 | #ifndef __clang__ /* FIXME */ | 134 | #ifndef __clang__ /* FIXME */ |
| 128 | #undef tmpfile | 135 | #undef tmpfile |
| 129 | __malloc(malloc (fclose, 1)) | 136 | __malloc(malloc (fclose, 1)) |
