summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorq662023-12-15 23:05:29 +0100
committerJulien Voisin2023-12-15 23:32:23 +0100
commit8d090c8a1a86408fa8b54029b97fccd17f9d35d5 (patch)
tree941e3cfb70300f8ecd5e79c21f7a5389e3ab87fc /include
parentc607773a80e6685ab4c922245c33cf2ea5dcfb72 (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.h53
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__
29extern "C" { 29extern "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))