summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorjvoisin2023-05-30 22:06:48 +0200
committerjvoisin2023-05-30 22:06:48 +0200
commit58168afc8b2328c24137820c5fbe7c9775901944 (patch)
tree6547738bd087258fc4c4bc6b6e703fd0cb215148 /include
parentc4247e4389b765179aa1fd0b010f50e8d6bddf4d (diff)
Add some __attribute__((access…)) annotations
See https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html for details
Diffstat (limited to 'include')
-rw-r--r--include/fortify-headers.h4
-rw-r--r--include/string.h23
2 files changed, 27 insertions, 0 deletions
diff --git a/include/fortify-headers.h b/include/fortify-headers.h
index a37cd4a..5a3c6e5 100644
--- a/include/fortify-headers.h
+++ b/include/fortify-headers.h
@@ -29,4 +29,8 @@
29#define __bos(ptr, type) __builtin_object_size (ptr, type) 29#define __bos(ptr, type) __builtin_object_size (ptr, type)
30#endif 30#endif
31 31
32#if defined __has_attribute && __has_attribute (access)
33#define __access(...) __attribute__ ((access (__VA_ARGS__)))
34#endif
35
32#endif 36#endif
diff --git a/include/string.h b/include/string.h
index 8685bb7..9b6e601 100644
--- a/include/string.h
+++ b/include/string.h
@@ -36,6 +36,8 @@ extern "C" {
36#undef strncat 36#undef strncat
37#undef strncpy 37#undef strncpy
38 38
39__access(write_only, 1)
40__access(read_only, 2, 3)
39_FORTIFY_FN(memcpy) void *memcpy(void *__od, const void *__os, size_t __n) 41_FORTIFY_FN(memcpy) void *memcpy(void *__od, const void *__os, size_t __n)
40{ 42{
41 size_t __bd = __bos(__od, 0); 43 size_t __bd = __bos(__od, 0);
@@ -53,6 +55,8 @@ _FORTIFY_FN(memcpy) void *memcpy(void *__od, const void *__os, size_t __n)
53 return __builtin_memcpy(__od, __os, __n); 55 return __builtin_memcpy(__od, __os, __n);
54} 56}
55 57
58__access(write_only, 1)
59__access(read_only, 2, 3)
56_FORTIFY_FN(memmove) void *memmove(void *__d, const void *__s, size_t __n) 60_FORTIFY_FN(memmove) void *memmove(void *__d, const void *__s, size_t __n)
57{ 61{
58 size_t __bd = __bos(__d, 0); 62 size_t __bd = __bos(__d, 0);
@@ -63,6 +67,7 @@ _FORTIFY_FN(memmove) void *memmove(void *__d, const void *__s, size_t __n)
63 return __orig_memmove(__d, __s, __n); 67 return __orig_memmove(__d, __s, __n);
64} 68}
65 69
70__access(write_only, 1)
66_FORTIFY_FN(memset) void *memset(void *__d, int __c, size_t __n) 71_FORTIFY_FN(memset) void *memset(void *__d, int __c, size_t __n)
67{ 72{
68 size_t __b = __bos(__d, 0); 73 size_t __b = __bos(__d, 0);
@@ -76,6 +81,8 @@ _FORTIFY_FN(memset) void *memset(void *__d, int __c, size_t __n)
76 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ 81 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
77 || defined(_BSD_SOURCE) 82 || defined(_BSD_SOURCE)
78#undef stpcpy 83#undef stpcpy
84__access(write_only, 1)
85__access(read_only, 2)
79_FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s) 86_FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s)
80{ 87{
81 size_t __b = __bos(__d, 0); 88 size_t __b = __bos(__d, 0);
@@ -86,6 +93,8 @@ _FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s)
86} 93}
87 94
88#undef stpncpy 95#undef stpncpy
96__access(write_only, 1)
97__access(read_only, 2, 3)
89_FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n) 98_FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n)
90{ 99{
91 size_t __b = __bos(__d, 0); 100 size_t __b = __bos(__d, 0);
@@ -96,6 +105,8 @@ _FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n)
96} 105}
97#endif 106#endif
98 107
108__access (read_write, 1)
109__access (read_only, 2)
99_FORTIFY_FN(strcat) char *strcat(char *__d, const char *__s) 110_FORTIFY_FN(strcat) char *strcat(char *__d, const char *__s)
100{ 111{
101 size_t __b = __bos(__d, 0); 112 size_t __b = __bos(__d, 0);
@@ -105,6 +116,8 @@ _FORTIFY_FN(strcat) char *strcat(char *__d, const char *__s)
105 return __orig_strcat(__d, __s); 116 return __orig_strcat(__d, __s);
106} 117}
107 118
119__access (write_only, 1)
120__access (read_only, 2)
108_FORTIFY_FN(strcpy) char *strcpy(char *__d, const char *__s) 121_FORTIFY_FN(strcpy) char *strcpy(char *__d, const char *__s)
109{ 122{
110 size_t __n = strlen(__s) + 1; 123 size_t __n = strlen(__s) + 1;
@@ -121,6 +134,8 @@ _FORTIFY_FN(strcpy) char *strcpy(char *__d, const char *__s)
121 return __orig_strcpy(__d, __s); 134 return __orig_strcpy(__d, __s);
122} 135}
123 136
137__access (read_write, 1)
138__access (read_only, 2, 3)
124_FORTIFY_FN(strncat) char *strncat(char *__d, const char *__s, size_t __n) 139_FORTIFY_FN(strncat) char *strncat(char *__d, const char *__s, size_t __n)
125{ 140{
126 size_t __b = __bos(__d, 0); 141 size_t __b = __bos(__d, 0);
@@ -137,6 +152,8 @@ _FORTIFY_FN(strncat) char *strncat(char *__d, const char *__s, size_t __n)
137 return __orig_strncat(__d, __s, __n); 152 return __orig_strncat(__d, __s, __n);
138} 153}
139 154
155__access (write_only, 1)
156__access (read_only, 2, 3)
140_FORTIFY_FN(strncpy) char *strncpy(char *__d, const char *__s, size_t __n) 157_FORTIFY_FN(strncpy) char *strncpy(char *__d, const char *__s, size_t __n)
141{ 158{
142 size_t __b = __bos(__d, 0); 159 size_t __b = __bos(__d, 0);
@@ -148,6 +165,8 @@ _FORTIFY_FN(strncpy) char *strncpy(char *__d, const char *__s, size_t __n)
148 165
149#ifdef _GNU_SOURCE 166#ifdef _GNU_SOURCE
150#undef mempcpy 167#undef mempcpy
168__access(write_only, 1)
169__access(read_only, 2, 3)
151_FORTIFY_FN(mempcpy) void *mempcpy(void *__d, const void *__s, size_t __n) 170_FORTIFY_FN(mempcpy) void *mempcpy(void *__d, const void *__s, size_t __n)
152{ 171{
153 size_t __bd = __bos(__d, 0); 172 size_t __bd = __bos(__d, 0);
@@ -162,6 +181,8 @@ _FORTIFY_FN(mempcpy) void *mempcpy(void *__d, const void *__s, size_t __n)
162#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 181#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
163#undef strlcat 182#undef strlcat
164#undef strlcpy 183#undef strlcpy
184__access (read_write, 1)
185__access (read_only, 2, 3)
165_FORTIFY_FN(strlcat) size_t strlcat(char *__d, const char *__s, size_t __n) 186_FORTIFY_FN(strlcat) size_t strlcat(char *__d, const char *__s, size_t __n)
166{ 187{
167 size_t __b = __bos(__d, 0); 188 size_t __b = __bos(__d, 0);
@@ -171,6 +192,8 @@ _FORTIFY_FN(strlcat) size_t strlcat(char *__d, const char *__s, size_t __n)
171 return __orig_strlcat(__d, __s, __n); 192 return __orig_strlcat(__d, __s, __n);
172} 193}
173 194
195__access (write_only, 1)
196__access (read_only, 2, 3)
174_FORTIFY_FN(strlcpy) size_t strlcpy(char *__d, const char *__s, size_t __n) 197_FORTIFY_FN(strlcpy) size_t strlcpy(char *__d, const char *__s, size_t __n)
175{ 198{
176 size_t __b = __bos(__d, 0); 199 size_t __b = __bos(__d, 0);