diff options
| author | sin | 2015-02-24 18:12:27 +0000 |
|---|---|---|
| committer | sin | 2015-02-24 18:14:33 +0000 |
| commit | eecef18261cc278fbc13ecbfb4e5bc10762cc794 (patch) | |
| tree | 483074e25fbbcbb198ac4d339b84ace4205987f6 /include/string.h | |
| parent | 9a77136c5914f6be50df195dac0f99424252a297 (diff) | |
Remove compile time checks
These can produce false positives. Given that we support fortify
source level 1 we shouldn't break valid code.
Diffstat (limited to 'include/string.h')
| -rw-r--r-- | include/string.h | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/include/string.h b/include/string.h index 9f69d31..9d40e77 100644 --- a/include/string.h +++ b/include/string.h | |||
| @@ -5,9 +5,6 @@ | |||
| 5 | 5 | ||
| 6 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 | 6 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 |
| 7 | 7 | ||
| 8 | #define __errordecl(name, msg) extern void name(void) __attribute__ ((__error__(msg))) | ||
| 9 | |||
| 10 | __errordecl(__memcpy_error, "memcpy: buffer overflow detected"); | ||
| 11 | static inline __attribute__ ((always_inline)) | 8 | static inline __attribute__ ((always_inline)) |
| 12 | void * | 9 | void * |
| 13 | __fortify_memcpy(void *dest, const void *src, size_t n) | 10 | __fortify_memcpy(void *dest, const void *src, size_t n) |
| @@ -16,9 +13,6 @@ __fortify_memcpy(void *dest, const void *src, size_t n) | |||
| 16 | char *d = dest; | 13 | char *d = dest; |
| 17 | const char *s = src; | 14 | const char *s = src; |
| 18 | 15 | ||
| 19 | if (__builtin_constant_p(n) && n > bos) | ||
| 20 | __memcpy_error(); | ||
| 21 | |||
| 22 | /* trap if pointers are overlapping but not if dest == src */ | 16 | /* trap if pointers are overlapping but not if dest == src */ |
| 23 | if ((d < s && d + n > s) || | 17 | if ((d < s && d + n > s) || |
| 24 | (s < d && s + n > d)) | 18 | (s < d && s + n > d)) |
| @@ -28,31 +22,23 @@ __fortify_memcpy(void *dest, const void *src, size_t n) | |||
| 28 | return memcpy(dest, src, n); | 22 | return memcpy(dest, src, n); |
| 29 | } | 23 | } |
| 30 | 24 | ||
| 31 | __errordecl(__memmove_error, "memmove: buffer overflow detected"); | ||
| 32 | static inline __attribute__ ((always_inline)) | 25 | static inline __attribute__ ((always_inline)) |
| 33 | void * | 26 | void * |
| 34 | __fortify_memmove(void *dest, const void *src, size_t n) | 27 | __fortify_memmove(void *dest, const void *src, size_t n) |
| 35 | { | 28 | { |
| 36 | size_t bos = __builtin_object_size(dest, 0); | 29 | size_t bos = __builtin_object_size(dest, 0); |
| 37 | 30 | ||
| 38 | if (__builtin_constant_p(n) && n > bos) | ||
| 39 | __memmove_error(); | ||
| 40 | |||
| 41 | if (n > bos) | 31 | if (n > bos) |
| 42 | __builtin_trap(); | 32 | __builtin_trap(); |
| 43 | return memmove(dest, src, n); | 33 | return memmove(dest, src, n); |
| 44 | } | 34 | } |
| 45 | 35 | ||
| 46 | __errordecl(__memset_error, "memset: buffer overflow detected"); | ||
| 47 | static inline __attribute__ ((always_inline)) | 36 | static inline __attribute__ ((always_inline)) |
| 48 | void * | 37 | void * |
| 49 | __fortify_memset(void *dest, int c, size_t n) | 38 | __fortify_memset(void *dest, int c, size_t n) |
| 50 | { | 39 | { |
| 51 | size_t bos = __builtin_object_size(dest, 0); | 40 | size_t bos = __builtin_object_size(dest, 0); |
| 52 | 41 | ||
| 53 | if (__builtin_constant_p(n) && n > bos) | ||
| 54 | __memset_error(); | ||
| 55 | |||
| 56 | if (n > bos) | 42 | if (n > bos) |
| 57 | __builtin_trap(); | 43 | __builtin_trap(); |
| 58 | return memset(dest, c, n); | 44 | return memset(dest, c, n); |
| @@ -69,16 +55,12 @@ __fortify_stpcpy(char *dest, const char *src) | |||
| 69 | return stpcpy(dest, src); | 55 | return stpcpy(dest, src); |
| 70 | } | 56 | } |
| 71 | 57 | ||
| 72 | __errordecl(__stpncpy_error, "stpncpy: buffer overflow detected"); | ||
| 73 | static inline __attribute__ ((always_inline)) | 58 | static inline __attribute__ ((always_inline)) |
| 74 | char * | 59 | char * |
| 75 | __fortify_stpncpy(char *dest, const char *src, size_t n) | 60 | __fortify_stpncpy(char *dest, const char *src, size_t n) |
| 76 | { | 61 | { |
| 77 | size_t bos = __builtin_object_size(dest, 0); | 62 | size_t bos = __builtin_object_size(dest, 0); |
| 78 | 63 | ||
| 79 | if (__builtin_constant_p(n) && n > bos) | ||
| 80 | __stpncpy_error(); | ||
| 81 | |||
| 82 | if (n > bos) | 64 | if (n > bos) |
| 83 | __builtin_trap(); | 65 | __builtin_trap(); |
| 84 | return stpncpy(dest, src, n); | 66 | return stpncpy(dest, src, n); |
| @@ -106,7 +88,6 @@ __fortify_strcpy(char *dest, const char *src) | |||
| 106 | return strcpy(dest, src); | 88 | return strcpy(dest, src); |
| 107 | } | 89 | } |
| 108 | 90 | ||
| 109 | __errordecl(__strncat_error, "strncat: buffer overflow detected"); | ||
| 110 | static inline __attribute__ ((always_inline)) | 91 | static inline __attribute__ ((always_inline)) |
| 111 | char * | 92 | char * |
| 112 | __fortify_strncat(char *dest, const char *src, size_t n) | 93 | __fortify_strncat(char *dest, const char *src, size_t n) |
| @@ -114,9 +95,6 @@ __fortify_strncat(char *dest, const char *src, size_t n) | |||
| 114 | size_t bos = __builtin_object_size(dest, 0); | 95 | size_t bos = __builtin_object_size(dest, 0); |
| 115 | size_t slen, dlen; | 96 | size_t slen, dlen; |
| 116 | 97 | ||
| 117 | if (__builtin_constant_p(n) && n > bos) | ||
| 118 | __strncat_error(); | ||
| 119 | |||
| 120 | if (n > bos) { | 98 | if (n > bos) { |
| 121 | slen = strlen(src); | 99 | slen = strlen(src); |
| 122 | dlen = strlen(dest); | 100 | dlen = strlen(dest); |
| @@ -128,32 +106,24 @@ __fortify_strncat(char *dest, const char *src, size_t n) | |||
| 128 | return strncat(dest, src, n); | 106 | return strncat(dest, src, n); |
| 129 | } | 107 | } |
| 130 | 108 | ||
| 131 | __errordecl(__strncpy_error, "strncpy: buffer overflow detected"); | ||
| 132 | static inline __attribute__ ((always_inline)) | 109 | static inline __attribute__ ((always_inline)) |
| 133 | char * | 110 | char * |
| 134 | __fortify_strncpy(char *dest, const char *src, size_t n) | 111 | __fortify_strncpy(char *dest, const char *src, size_t n) |
| 135 | { | 112 | { |
| 136 | size_t bos = __builtin_object_size(dest, 0); | 113 | size_t bos = __builtin_object_size(dest, 0); |
| 137 | 114 | ||
| 138 | if (__builtin_constant_p(n) && n > bos) | ||
| 139 | __strncpy_error(); | ||
| 140 | |||
| 141 | if (n > bos) | 115 | if (n > bos) |
| 142 | __builtin_trap(); | 116 | __builtin_trap(); |
| 143 | return strncpy(dest, src, n); | 117 | return strncpy(dest, src, n); |
| 144 | } | 118 | } |
| 145 | 119 | ||
| 146 | #ifdef _GNU_SOURCE | 120 | #ifdef _GNU_SOURCE |
| 147 | __errordecl(__mempcpy_error, "mempcpy: buffer overflow detected"); | ||
| 148 | static inline __attribute__ ((always_inline)) | 121 | static inline __attribute__ ((always_inline)) |
| 149 | void * | 122 | void * |
| 150 | __fortify_mempcpy(void *dest, const void *src, size_t n) | 123 | __fortify_mempcpy(void *dest, const void *src, size_t n) |
| 151 | { | 124 | { |
| 152 | size_t bos = __builtin_object_size(dest, 0); | 125 | size_t bos = __builtin_object_size(dest, 0); |
| 153 | 126 | ||
| 154 | if (__builtin_constant_p(n) && n > bos) | ||
| 155 | __mempcpy_error(); | ||
| 156 | |||
| 157 | if (n > bos) | 127 | if (n > bos) |
| 158 | __builtin_trap(); | 128 | __builtin_trap(); |
| 159 | return mempcpy(dest, src, n); | 129 | return mempcpy(dest, src, n); |
| @@ -161,31 +131,23 @@ __fortify_mempcpy(void *dest, const void *src, size_t n) | |||
| 161 | #endif | 131 | #endif |
| 162 | 132 | ||
| 163 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | 133 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
| 164 | __errordecl(__strlcat_error, "strlcat: buffer overflow detected"); | ||
| 165 | static inline __attribute__ ((always_inline)) | 134 | static inline __attribute__ ((always_inline)) |
| 166 | size_t | 135 | size_t |
| 167 | __fortify_strlcat(char *dest, const char *src, size_t n) | 136 | __fortify_strlcat(char *dest, const char *src, size_t n) |
| 168 | { | 137 | { |
| 169 | size_t bos = __builtin_object_size(dest, 0); | 138 | size_t bos = __builtin_object_size(dest, 0); |
| 170 | 139 | ||
| 171 | if (__builtin_constant_p(n) && n > bos) | ||
| 172 | __strlcat_error(); | ||
| 173 | |||
| 174 | if (n > bos) | 140 | if (n > bos) |
| 175 | __builtin_trap(); | 141 | __builtin_trap(); |
| 176 | return strlcat(dest, src, n); | 142 | return strlcat(dest, src, n); |
| 177 | } | 143 | } |
| 178 | 144 | ||
| 179 | __errordecl(__strlcpy_error, "strlcpy: buffer overflow detected"); | ||
| 180 | static inline __attribute__ ((always_inline)) | 145 | static inline __attribute__ ((always_inline)) |
| 181 | size_t | 146 | size_t |
| 182 | __fortify_strlcpy(char *dest, const char *src, size_t n) | 147 | __fortify_strlcpy(char *dest, const char *src, size_t n) |
| 183 | { | 148 | { |
| 184 | size_t bos = __builtin_object_size(dest, 0); | 149 | size_t bos = __builtin_object_size(dest, 0); |
| 185 | 150 | ||
| 186 | if (__builtin_constant_p(n) && n > bos) | ||
| 187 | __strlcpy_error(); | ||
| 188 | |||
| 189 | if (n > bos) | 151 | if (n > bos) |
| 190 | __builtin_trap(); | 152 | __builtin_trap(); |
| 191 | return strlcpy(dest, src, n); | 153 | return strlcpy(dest, src, n); |
| @@ -223,8 +185,6 @@ __fortify_strlcpy(char *dest, const char *src, size_t n) | |||
| 223 | #define strlcpy(dest, src, n) __fortify_strlcpy(dest, src, n) | 185 | #define strlcpy(dest, src, n) __fortify_strlcpy(dest, src, n) |
| 224 | #endif | 186 | #endif |
| 225 | 187 | ||
| 226 | #undef __errordecl | ||
| 227 | |||
| 228 | #endif | 188 | #endif |
| 229 | 189 | ||
| 230 | #endif | 190 | #endif |
