diff options
| author | jvoisin | 2023-09-22 18:27:54 +0200 |
|---|---|---|
| committer | jvoisin | 2023-09-22 18:30:35 +0200 |
| commit | 75b95fa25df74fcd0498bf59e3524f20f594755d (patch) | |
| tree | 729ba69a2358566f126a8b20f9f30d7a5f7f249c /include/stdio.h | |
| parent | 8c2352b985b1bf69efb965ba15f5e300eb7e8e12 (diff) | |
Add more __diagnose_as_builtin annotations
Diffstat (limited to 'include/stdio.h')
| -rw-r--r-- | include/stdio.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/include/stdio.h b/include/stdio.h index 000a72d..582be4f 100644 --- a/include/stdio.h +++ b/include/stdio.h | |||
| @@ -40,12 +40,18 @@ extern "C" { | |||
| 40 | #undef vsprintf | 40 | #undef vsprintf |
| 41 | 41 | ||
| 42 | __access(read_only, 2) | 42 | __access(read_only, 2) |
| 43 | #if __has_builtin(__builtin_fdopen) | ||
| 44 | __diagnose_as_builtin(__builtin_fdopen, 1, 2) | ||
| 45 | #endif | ||
| 43 | _FORTIFY_FN(fdopen) FILE *fdopen(int __f, const char* _FORTIFY_POS0 __m) | 46 | _FORTIFY_FN(fdopen) FILE *fdopen(int __f, const char* _FORTIFY_POS0 __m) |
| 44 | { | 47 | { |
| 45 | return __orig_fdopen(__f, __m); | 48 | return __orig_fdopen(__f, __m); |
| 46 | } | 49 | } |
| 47 | 50 | ||
| 48 | __access(write_only, 1, 2) | 51 | __access(write_only, 1, 2) |
| 52 | #if __has_builtin(__builtin_fgets) | ||
| 53 | __diagnose_as_builtin(__builtin_fgets, 1, 2, 3) | ||
| 54 | #endif | ||
| 49 | _FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f) | 55 | _FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f) |
| 50 | { | 56 | { |
| 51 | size_t __b = __bos(__s, 0); | 57 | size_t __b = __bos(__s, 0); |
| @@ -56,6 +62,9 @@ _FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f) | |||
| 56 | } | 62 | } |
| 57 | 63 | ||
| 58 | __malloc(malloc (fclose, 1)) | 64 | __malloc(malloc (fclose, 1)) |
| 65 | #if __has_builtin(__builtin_fmemopen) | ||
| 66 | __diagnose_as_builtin(__builtin_fmemopen, 1, 2, 3) | ||
| 67 | #endif | ||
| 59 | _FORTIFY_FN(fmemopen) FILE *fmemopen(void* _FORTIFY_POS0 __b, size_t __s, const char* _FORTIFY_POS0 __m) | 68 | _FORTIFY_FN(fmemopen) FILE *fmemopen(void* _FORTIFY_POS0 __b, size_t __s, const char* _FORTIFY_POS0 __m) |
| 60 | { | 69 | { |
| 61 | return __orig_fmemopen(__b, __s, __m); | 70 | return __orig_fmemopen(__b, __s, __m); |
| @@ -64,12 +73,18 @@ _FORTIFY_FN(fmemopen) FILE *fmemopen(void* _FORTIFY_POS0 __b, size_t __s, const | |||
| 64 | __access(read_only, 1) | 73 | __access(read_only, 1) |
| 65 | __access(read_only, 2) | 74 | __access(read_only, 2) |
| 66 | __malloc(malloc (fclose, 1)) | 75 | __malloc(malloc (fclose, 1)) |
| 76 | #if __has_builtin(__builtin_fopen) | ||
| 77 | __diagnose_as_builtin(__builtin_fopen, 1, 2) | ||
| 78 | #endif | ||
| 67 | _FORTIFY_FN(fopen) FILE *fopen(const char* _FORTIFY_POS0 __p, const char* _FORTIFY_POS0 __m) | 79 | _FORTIFY_FN(fopen) FILE *fopen(const char* _FORTIFY_POS0 __p, const char* _FORTIFY_POS0 __m) |
| 68 | { | 80 | { |
| 69 | return __orig_fopen(__p, __m); | 81 | return __orig_fopen(__p, __m); |
| 70 | } | 82 | } |
| 71 | 83 | ||
| 72 | __access(write_only, 1) | 84 | __access(write_only, 1) |
| 85 | #if __has_builtin(__builtin_fread) | ||
| 86 | __diagnose_as_builtin(__builtin_fread, 1, 2, 3, 4) | ||
| 87 | #endif | ||
| 73 | _FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n, | 88 | _FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n, |
| 74 | size_t __m, FILE *__f) | 89 | size_t __m, FILE *__f) |
| 75 | { | 90 | { |
| @@ -83,6 +98,9 @@ _FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n, | |||
| 83 | } | 98 | } |
| 84 | 99 | ||
| 85 | __access(read_only, 1) | 100 | __access(read_only, 1) |
| 101 | #if __has_builtin(__builtin_fwrite) | ||
| 102 | __diagnose_as_builtin(__builtin_fwrite, 1, 2, 3, 4) | ||
| 103 | #endif | ||
| 86 | _FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n, | 104 | _FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n, |
| 87 | size_t __m, FILE *__f) | 105 | size_t __m, FILE *__f) |
| 88 | { | 106 | { |
| @@ -98,6 +116,9 @@ _FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n, | |||
| 98 | __access(read_only, 1) | 116 | __access(read_only, 1) |
| 99 | __access(read_only, 2) | 117 | __access(read_only, 2) |
| 100 | __malloc(malloc (pclose, 1)) | 118 | __malloc(malloc (pclose, 1)) |
| 119 | #if __has_builtin(__builtin_popen) | ||
| 120 | __diagnose_as_builtin(__builtin_popen, 1, 2) | ||
| 121 | #endif | ||
| 101 | _FORTIFY_FN(popen) FILE *popen(const char* _FORTIFY_POS0 __c, const char* _FORTIFY_POS0 __t) | 122 | _FORTIFY_FN(popen) FILE *popen(const char* _FORTIFY_POS0 __c, const char* _FORTIFY_POS0 __t) |
| 102 | { | 123 | { |
| 103 | return __orig_popen(__c, __t); | 124 | return __orig_popen(__c, __t); |
| @@ -106,6 +127,9 @@ _FORTIFY_FN(popen) FILE *popen(const char* _FORTIFY_POS0 __c, const char* _FORTI | |||
| 106 | #ifndef __clang__ /* FIXME */ | 127 | #ifndef __clang__ /* FIXME */ |
| 107 | #undef tmpfile | 128 | #undef tmpfile |
| 108 | __malloc(malloc (fclose, 1)) | 129 | __malloc(malloc (fclose, 1)) |
| 130 | #if __has_builtin(__builtin_tmpfile) | ||
| 131 | __diagnose_as_builtin(__builtin_tmpfile) | ||
| 132 | #endif | ||
| 109 | _FORTIFY_FN(tmpfile) FILE *tmpfile(void) | 133 | _FORTIFY_FN(tmpfile) FILE *tmpfile(void) |
| 110 | { | 134 | { |
| 111 | return __orig_tmpfile(); | 135 | return __orig_tmpfile(); |
| @@ -162,6 +186,8 @@ _FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f, | |||
| 162 | * have the __chk variants, we'd need to implement a body with intermediate | 186 | * have the __chk variants, we'd need to implement a body with intermediate |
| 163 | * variables within the macro, which means more non-portable mess | 187 | * variables within the macro, which means more non-portable mess |
| 164 | * 3) not implementing these under clang, which is what we do for now | 188 | * 3) not implementing these under clang, which is what we do for now |
| 189 | * | ||
| 190 | * TODO: add __diagnose_as_builtin | ||
| 165 | */ | 191 | */ |
| 166 | 192 | ||
| 167 | #undef snprintf | 193 | #undef snprintf |
