4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-22 00:38:06 +08:00

Protect strncat from accessing an unaligend long pointer

- fixes Bug libc/32679
This commit is contained in:
Jeff Johnston 2025-02-11 14:28:33 -05:00
parent 68c13dc92f
commit a473f960e5

View File

@ -63,15 +63,18 @@ strncat (char *__restrict s1,
while (UNALIGNED_X(s1) && *s1)
s1++;
/* Skip over the aligned data in s1 as quickly as possible. */
unsigned long *aligned_s1 = (unsigned long *)s1;
while (!DETECT_NULL(*aligned_s1))
aligned_s1++;
s1 = (char *)aligned_s1;
if (*s1)
{
/* Skip over the aligned data in s1 as quickly as possible. */
unsigned long *aligned_s1 = (unsigned long *)s1;
while (!DETECT_NULL(*aligned_s1))
aligned_s1++;
s1 = (char *)aligned_s1;
/* Find string terminator. */
while (*s1)
s1++;
/* Find string terminator. */
while (*s1)
s1++;
}
/* s1 now points to the its trailing null character, now copy
up to N bytes from S2 into S1 stopping if a NULL is encountered