summaryrefslogtreecommitdiff
path: root/include/string.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/string.h')
-rw-r--r--include/string.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/include/string.h b/include/string.h
index 9b6e601..f416a51 100644
--- a/include/string.h
+++ b/include/string.h
@@ -156,8 +156,13 @@ __access (write_only, 1)
156__access (read_only, 2, 3) 156__access (read_only, 2, 3)
157_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)
158{ 158{
159 size_t __b = __bos(__d, 0); 159 /* trap if pointers are overlapping but not if dst == src.
160 * gcc seems to like to generate code that relies on dst == src */
161 if ((__d < __s && __d + __n > __s) ||
162 (__s < __d && __s + __n > __d))
163 __builtin_trap();
160 164
165 size_t __b = __bos(__d, 0);
161 if (__n > __b) 166 if (__n > __b)
162 __builtin_trap(); 167 __builtin_trap();
163 return __orig_strncpy(__d, __s, __n); 168 return __orig_strncpy(__d, __s, __n);