1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-28 00:21:52 +03:00

Fix x86 strncat optimized implementation for large sizes

Similar to BZ#19387, BZ#21014, and BZ#20971, both x86 sse2 strncat
optimized assembly implementations do not handle the size overflow
correctly.

The x86_64 one is in fact an issue with strcpy-sse2-unaligned, but
that is triggered also with strncat optimized implementation.

This patch uses a similar strategy used on 3daef2c8ee, where
saturared math is used for overflow case.

Checked on x86_64-linux-gnu and i686-linux-gnu.  It fixes BZ #19390.

	[BZ #19390]
	* string/test-strncat.c (test_main): Add tests with SIZE_MAX as
	maximum string size.
	* sysdeps/i386/i686/multiarch/strcat-sse2.S (STRCAT): Avoid overflow
	in pointer addition.
	* sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S (STRCPY):
	Likewise.
This commit is contained in:
Adhemerval Zanella
2017-01-03 12:19:12 -02:00
parent d4d629e618
commit 8dad72997a
4 changed files with 29 additions and 0 deletions

View File

@ -284,12 +284,23 @@ test_main (void)
do_test (0, 0, 8, 8, n, SMALL_CHAR);
do_test (0, 8, 8, 8, n, SMALL_CHAR);
do_test (0, 2, 2, 2, SIZE_MAX, SMALL_CHAR);
do_test (0, 0, 4, 4, SIZE_MAX, SMALL_CHAR);
do_test (4, 0, 4, 4, SIZE_MAX, BIG_CHAR);
do_test (0, 0, 8, 8, SIZE_MAX, SMALL_CHAR);
do_test (0, 8, 8, 8, SIZE_MAX, SMALL_CHAR);
for (i = 1; i < 8; ++i)
{
do_test (0, 0, 8 << i, 8 << i, n, SMALL_CHAR);
do_test (8 - i, 2 * i, 8 << i, 8 << i, n, SMALL_CHAR);
do_test (0, 0, 8 << i, 2 << i, n, SMALL_CHAR);
do_test (8 - i, 2 * i, 8 << i, 2 << i, n, SMALL_CHAR);
do_test (0, 0, 8 << i, 8 << i, SIZE_MAX, SMALL_CHAR);
do_test (8 - i, 2 * i, 8 << i, 8 << i, SIZE_MAX, SMALL_CHAR);
do_test (0, 0, 8 << i, 2 << i, SIZE_MAX, SMALL_CHAR);
do_test (8 - i, 2 * i, 8 << i, 2 << i, SIZE_MAX, SMALL_CHAR);
}
for (i = 1; i < 8; ++i)
@ -297,6 +308,10 @@ test_main (void)
do_test (i, 2 * i, 8 << i, 1, n, SMALL_CHAR);
do_test (2 * i, i, 8 << i, 1, n, BIG_CHAR);
do_test (i, i, 8 << i, 10, n, SMALL_CHAR);
do_test (i, 2 * i, 8 << i, 1, SIZE_MAX, SMALL_CHAR);
do_test (2 * i, i, 8 << i, 1, SIZE_MAX, BIG_CHAR);
do_test (i, i, 8 << i, 10, SIZE_MAX, SMALL_CHAR);
}
}