This is an automated email from the ASF dual-hosted git repository. bcall pushed a commit to branch fix-fedora42-stringop-truncation in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit df1d817a1e38dd4026ef80929f8b249fef254d46 Author: Bryan Call <[email protected]> AuthorDate: Fri Oct 24 10:16:36 2025 -0700 Fix stringop-truncation warning in ats_unix_append_id Replace strncat with memcpy to satisfy GCC's -Werror=stringop-truncation warning. The original code was safe due to the bounds check, but GCC couldn't determine this. Using memcpy makes the intent clearer and eliminates the warning. --- include/tscore/ink_inet.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/tscore/ink_inet.h b/include/tscore/ink_inet.h index cc9a07a0e8..17fb26ec32 100644 --- a/include/tscore/ink_inet.h +++ b/include/tscore/ink_inet.h @@ -323,9 +323,10 @@ inline void ats_unix_append_id(sockaddr_un *s, int id) { char tmp[16]; - int cnt = snprintf(tmp, sizeof(tmp), "-%d", id); - if (static_cast<size_t>(ats_unix_path_len(s) + cnt) < TS_UNIX_SIZE) { - strncat(s->sun_path, tmp, cnt); + int cnt = snprintf(tmp, sizeof(tmp), "-%d", id); + int old_len = ats_unix_path_len(s); + if (static_cast<size_t>(old_len + cnt) < TS_UNIX_SIZE) { + memcpy(s->sun_path + old_len, tmp, cnt + 1); // +1 to include the null terminator #if HAVE_STRUCT_SOCKADDR_UN_SUN_LEN s->sun_len = SUN_LEN(s); #endif
