For example, in strcpy (ignoring the UB overlapping check):
|
size_t __n = strlen(__s) + 1; |
|
|
|
/* trap if pointers are overlapping but not if dst == src. |
|
* gcc seems to like to generate code that relies on dst == src */ |
|
if ((__d < __s && __d + __n > __s) || |
|
(__s < __d && __s + __n > __d)) |
|
__builtin_trap(); |
|
|
|
size_t __b = __bos(__d, 0); |
|
if (__n > __b) |
|
__builtin_trap(); |
|
return __orig_strcpy(__d, __s); |
By the time, __orig_strcpy is called, the length has already been computed and has been established to be in bound. There's no need to pay for the nul-byte search again inside of __orig_strcpy when the faster memcpy can be called instead.
Some of the other str* functions suffer from the same issue.
For example, in
strcpy(ignoring the UB overlapping check):fortify-headers/include/string.h
Lines 139 to 150 in 9aa4490
By the time,
__orig_strcpyis called, the length has already been computed and has been established to be in bound. There's no need to pay for the nul-byte search again inside of__orig_strcpywhen the fastermemcpycan be called instead.Some of the other
str*functions suffer from the same issue.