summaryrefslogtreecommitdiff
path: root/include/string.h
diff options
context:
space:
mode:
authorjvoisin2023-06-22 17:58:58 +0200
committerjvoisin2023-06-22 17:58:58 +0200
commitaf7480d0190cb5dcf279a7ddfab320ff084a3471 (patch)
tree3ba3190adb08bd5d3a4671358c5ae4c3c13f3ab2 /include/string.h
parentcb1ce9e1815a492de0f13c2b046b8472024b9f6d (diff)
Add tests for stpcpy
Diffstat (limited to 'include/string.h')
-rw-r--r--include/string.h13
1 files changed, 10 insertions, 3 deletions
diff --git a/include/string.h b/include/string.h
index f416a51..f738901 100644
--- a/include/string.h
+++ b/include/string.h
@@ -85,9 +85,16 @@ __access(write_only, 1)
85__access(read_only, 2) 85__access(read_only, 2)
86_FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s) 86_FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s)
87{ 87{
88 size_t __b = __bos(__d, 0); 88 size_t __n = strlen(__s) + 1;
89 89
90 if (strlen(__s) + 1 > __b) 90 /* trap if pointers are overlapping but not if dst == src.
91 * gcc seems to like to generate code that relies on dst == src */
92 if ((__d < __s && __d + __n > __s) ||
93 (__s < __d && __s + __n > __d))
94 __builtin_trap();
95
96 size_t __b = __bos(__d, 0);
97 if (__n > __b)
91 __builtin_trap(); 98 __builtin_trap();
92 return __orig_stpcpy(__d, __s); 99 return __orig_stpcpy(__d, __s);
93} 100}
@@ -129,7 +136,7 @@ _FORTIFY_FN(strcpy) char *strcpy(char *__d, const char *__s)
129 __builtin_trap(); 136 __builtin_trap();
130 137
131 size_t __b = __bos(__d, 0); 138 size_t __b = __bos(__d, 0);
132 if (strlen(__s) + 1 > __b) 139 if (__n > __b)
133 __builtin_trap(); 140 __builtin_trap();
134 return __orig_strcpy(__d, __s); 141 return __orig_strcpy(__d, __s);
135} 142}