summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/fortify-headers.h4
-rw-r--r--include/string.h8
-rw-r--r--tests/Makefile1
-rw-r--r--tests/test_issue57.c11
4 files changed, 17 insertions, 7 deletions
diff --git a/include/fortify-headers.h b/include/fortify-headers.h
index ea2e430..796fd2d 100644
--- a/include/fortify-headers.h
+++ b/include/fortify-headers.h
@@ -141,8 +141,8 @@
141 * since gcc seems to like to generate code that relies on dst == src */ 141 * since gcc seems to like to generate code that relies on dst == src */
142#define __fh_overlap(a, len_a, b, len_b) \ 142#define __fh_overlap(a, len_a, b, len_b) \
143 ( \ 143 ( \
144 ((a) < (b) && (b) < (a) + (__fh_size_t)(len_a)) \ 144 ((a) < (b) && (b) < ((a) + (__fh_size_t)(len_a))) \
145 || ((b) < (a) && (a) < (b) + (__fh_size_t)(len_b)) \ 145 || ((b) < (a) && (a) < ((b) + (__fh_size_t)(len_b))) \
146 ) 146 )
147 147
148/* 148/*
diff --git a/include/string.h b/include/string.h
index 071d592..924be49 100644
--- a/include/string.h
+++ b/include/string.h
@@ -58,10 +58,8 @@ __error_if((__fh_bos(__od, 0) < __n), "'memcpy' called with `n` bigger than the
58 58
59 __fh_size_t __bd = __fh_bos(__od, 0); 59 __fh_size_t __bd = __fh_bos(__od, 0);
60 __fh_size_t __bs = __fh_bos(__os, 0); 60 __fh_size_t __bs = __fh_bos(__os, 0);
61 char *__d = (char *)__od;
62 const char *__s = (const char *)__os;
63 61
64 if __fh_overlap(__d, __bd, __s, __n) 62 if __fh_overlap(__od, __n, __os, __n)
65 __builtin_trap(); 63 __builtin_trap();
66 if (__n > __bd || __n > __bs) 64 if (__n > __bd || __n > __bs)
67 __builtin_trap(); 65 __builtin_trap();
@@ -189,7 +187,7 @@ _FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s)
189 __fh_size_t __n = strlen(__s) + 1; 187 __fh_size_t __n = strlen(__s) + 1;
190 __fh_size_t __b = __fh_bos(__d, 0); 188 __fh_size_t __b = __fh_bos(__d, 0);
191 189
192 if (__fh_overlap(__d, __b, __s, __n)) 190 if (__fh_overlap(__d, __n, __s, __n))
193 __builtin_trap(); 191 __builtin_trap();
194 192
195 if (__n > __b) 193 if (__n > __b)
@@ -257,7 +255,7 @@ _FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s)
257 __fh_size_t __n = strlen(__s) + 1; 255 __fh_size_t __n = strlen(__s) + 1;
258 __fh_size_t __b = __fh_bos(__d, 0); 256 __fh_size_t __b = __fh_bos(__d, 0);
259 257
260 if (__fh_overlap(__d, __b, __s, __n)) 258 if (__fh_overlap(__d, __n, __s, __n))
261 __builtin_trap(); 259 __builtin_trap();
262 260
263 if (__n > __b) 261 if (__n > __b)
diff --git a/tests/Makefile b/tests/Makefile
index 8faf11a..81a1943 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -42,6 +42,7 @@ RUNTIME_TARGETS= \
42 test_gethostname_static \ 42 test_gethostname_static \
43 test_getlogin_r_dynamic \ 43 test_getlogin_r_dynamic \
44 test_getlogin_r_static \ 44 test_getlogin_r_static \
45 test_issue57 \
45 test_mbsrtowcs_dynamic \ 46 test_mbsrtowcs_dynamic \
46 test_mbsrtowcs_static \ 47 test_mbsrtowcs_static \
47 test_mbstowcs_dynamic \ 48 test_mbstowcs_dynamic \
diff --git a/tests/test_issue57.c b/tests/test_issue57.c
new file mode 100644
index 0000000..ee9c38e
--- /dev/null
+++ b/tests/test_issue57.c
@@ -0,0 +1,11 @@
1#include "common.h"
2
3#include <string.h>
4
5int main(int argc, char** argv) {
6 char buffer[32];
7 memcpy(buffer , buffer + 16, 16);
8 puts(buffer);
9
10 return ret;
11}