summaryrefslogtreecommitdiff
path: root/include/string.h
diff options
context:
space:
mode:
authorsin2015-02-24 18:12:27 +0000
committersin2015-02-24 18:14:33 +0000
commiteecef18261cc278fbc13ecbfb4e5bc10762cc794 (patch)
tree483074e25fbbcbb198ac4d339b84ace4205987f6 /include/string.h
parent9a77136c5914f6be50df195dac0f99424252a297 (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.h40
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");
11static inline __attribute__ ((always_inline)) 8static inline __attribute__ ((always_inline))
12void * 9void *
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");
32static inline __attribute__ ((always_inline)) 25static inline __attribute__ ((always_inline))
33void * 26void *
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");
47static inline __attribute__ ((always_inline)) 36static inline __attribute__ ((always_inline))
48void * 37void *
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");
73static inline __attribute__ ((always_inline)) 58static inline __attribute__ ((always_inline))
74char * 59char *
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");
110static inline __attribute__ ((always_inline)) 91static inline __attribute__ ((always_inline))
111char * 92char *
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");
132static inline __attribute__ ((always_inline)) 109static inline __attribute__ ((always_inline))
133char * 110char *
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");
148static inline __attribute__ ((always_inline)) 121static inline __attribute__ ((always_inline))
149void * 122void *
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");
165static inline __attribute__ ((always_inline)) 134static inline __attribute__ ((always_inline))
166size_t 135size_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");
180static inline __attribute__ ((always_inline)) 145static inline __attribute__ ((always_inline))
181size_t 146size_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