diff options
Diffstat (limited to 'include/string.h')
| -rw-r--r-- | include/string.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/include/string.h b/include/string.h index f738901..9bf17a0 100644 --- a/include/string.h +++ b/include/string.h | |||
| @@ -104,8 +104,13 @@ __access(write_only, 1) | |||
| 104 | __access(read_only, 2, 3) | 104 | __access(read_only, 2, 3) |
| 105 | _FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n) | 105 | _FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n) |
| 106 | { | 106 | { |
| 107 | size_t __b = __bos(__d, 0); | 107 | /* trap if pointers are overlapping but not if dst == src. |
| 108 | * gcc seems to like to generate code that relies on dst == src */ | ||
| 109 | if ((__d < __s && __d + __n > __s) || | ||
| 110 | (__s < __d && __s + __n > __d)) | ||
| 111 | __builtin_trap(); | ||
| 108 | 112 | ||
| 113 | size_t __b = __bos(__d, 0); | ||
| 109 | if (__n > __b && strlen(__s) + 1 > __b) | 114 | if (__n > __b && strlen(__s) + 1 > __b) |
| 110 | __builtin_trap(); | 115 | __builtin_trap(); |
| 111 | return __orig_stpncpy(__d, __s, __n); | 116 | return __orig_stpncpy(__d, __s, __n); |
