From 8dad72997af2be0dc72a4bc7dbe82d85c90334fc Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Tue, 3 Jan 2017 12:19:12 -0200 Subject: 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 3daef2c8ee4df2, 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. --- sysdeps/i386/i686/multiarch/strcat-sse2.S | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sysdeps/i386/i686') diff --git a/sysdeps/i386/i686/multiarch/strcat-sse2.S b/sysdeps/i386/i686/multiarch/strcat-sse2.S index 145ae66894..6359c7330c 100644 --- a/sysdeps/i386/i686/multiarch/strcat-sse2.S +++ b/sysdeps/i386/i686/multiarch/strcat-sse2.S @@ -227,6 +227,8 @@ L(StartStrcpyPart): pxor %xmm0, %xmm0 # ifdef USE_AS_STRNCAT add %ecx, %ebx + sbb %edx, %edx + or %edx, %ebx # endif sub %ecx, %eax jmp L(Unalign16Both) -- cgit 1.4.1