[Bug 280146] Incorrect operation of strcpy/strncpy (libc.so.7)
Date: Fri, 05 Jul 2024 22:06:30 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=280146 Bug ID: 280146 Summary: Incorrect operation of strcpy/strncpy (libc.so.7) Product: Base System Version: 14.1-RELEASE Hardware: amd64 OS: Any Status: New Severity: Affects Many People Priority: --- Component: bin Assignee: bugs@FreeBSD.org Reporter: work+freebsd@vvv.kiev.ua Starting from 14.1 strcpy/strncpy functions don't work correctly in some cases. The following simple program prints wrong result with strcpy: #include <stdio.h> #include <string.h> int main(void) { char str[1024] = "0a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x"; printf("%s\n", str); strcpy(str, str + 1); printf("%s\n", str); return 0; } Actual result: 0a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p67r8s9t0u1v2w3xx Expected result: 0a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x And with strncpy: #include <stdio.h> #include <string.h> int main(void) { char str[1024] = "0a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x"; printf("%s\n", str); strncpy(str, str + 1, strlen(str)); printf("%s\n", str); return 0; } Actual result: 0a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p Expected result: 0a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x Both programs work correctly in 13.3, 14.0 and older. -- You are receiving this mail because: You are the assignee for the bug.