diff options
| author | jvoisin | 2023-05-30 22:06:48 +0200 |
|---|---|---|
| committer | jvoisin | 2023-05-30 22:06:48 +0200 |
| commit | 58168afc8b2328c24137820c5fbe7c9775901944 (patch) | |
| tree | 6547738bd087258fc4c4bc6b6e703fd0cb215148 /include | |
| parent | c4247e4389b765179aa1fd0b010f50e8d6bddf4d (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.h | 4 | ||||
| -rw-r--r-- | include/string.h | 23 |
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); |
