lib:replace: Avoid overlapping strncpy calls, replace with memmove
In bsd_attr_list() buffers that can overlap are copied using strncpy, but this is undefined behavior, and is now detected in FreeBSD after samba started to be built with _FORTIFY_SOURCE=3. This results in a SIGABRT as soon as any extended attributes are processed:
#0 kill () at kill.S:4
#1 0x0000000800ccb121 in __fail (msg=0x800bd0a20 "buffer overflow detected; terminated") at /usr/src/lib/libc/secure/libc_stack_protector.c:119
#2 0x0000000800ccb140 in __chk_fail () at /usr/src/lib/libc/secure/libc_stack_protector.c:132
#3 0x0000000800ccaf03 in __strncpy_chk (dst=0x217a <error: Cannot access memory at address 0x217a>, src=0x6 <error: Cannot access memory at address 0x6>, len=0, slen=<optimized out>) at /usr/src/lib/libc/secure/strncpy_chk.c:50
#4 0x0000000800586825 in __strncpy_ichk (dst=0x7fffffffc2d5 "", src=0x7fffffffc2db "org.netatalk.Metadata$org.netatalk.has-Extended-Attributes", len=21) at /usr/include/ssp/string.h:120
#5 bsd_attr_list (type=0, arg=..., list=0x7fffffffc2d5 "", size=1024) at ../../lib/replace/xattr.c:284Replace the strncpy calls with memmove, since in this particular case the result is equivalent.
Checklist
- Commits have
Signed-off-by:with name/author being identical to the commit author - (optional) This MR is just one part towards a larger feature.
- (optional, if backport required) Bugzilla bug filed and
BUG:tag added - Test suite updated with functionality tests
- Test suite updated with negative tests
- Documentation updated
- CI timeout is 3h or higher (see Settings/CICD/General pipelines/ Timeout)
Reviewer's checklist:
- There is a test suite reasonably covering new functionality or modifications
- Function naming, parameters, return values, types, etc., are consistent
and according to
README.Coding.md - This feature/change has adequate documentation added
- No obvious mistakes in the code