[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[commits] r14644 - in /fsf/trunk/libc: ./ string/ sysdeps/x86_64/multiarch/



Author: eglibc
Date: Fri Jul 22 00:06:11 2011
New Revision: 14644

Log:
Import glibc-mainline for 2011-07-22

Modified:
    fsf/trunk/libc/ChangeLog
    fsf/trunk/libc/string/tester.c
    fsf/trunk/libc/sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S
    fsf/trunk/libc/sysdeps/x86_64/multiarch/strcpy-ssse3.S

Modified: fsf/trunk/libc/ChangeLog
==============================================================================
--- fsf/trunk/libc/ChangeLog (original)
+++ fsf/trunk/libc/ChangeLog Fri Jul 22 00:06:11 2011
@@ -1,3 +1,15 @@
+2011-07-21  Liubov Dmitrieva  <liubov.dmitrieva@xxxxxxxxx>
+
+	* sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S: Fix overfow
+	bug in strncpy/strncat.
+	* sysdeps/x86_64/multiarch/strcpy-ssse3.S: Likewise.
+
+2011-07-21  Ulrich Drepper  <drepper@xxxxxxxxx>
+
+	* string/tester.c (test_strcat): Add tests for different alignments
+	of source and destination.
+	(test_strncat): Likewise.
+
 2011-07-20  Ulrich Drepper  <drepper@xxxxxxxxx>
 
 	[BZ #12852]

Modified: fsf/trunk/libc/string/tester.c
==============================================================================
--- fsf/trunk/libc/string/tester.c (original)
+++ fsf/trunk/libc/string/tester.c Fri Jul 22 00:06:11 2011
@@ -1,5 +1,6 @@
 /* Tester for string functions.
-   Copyright (C) 1995-2001, 2003, 2005, 2008, 2010 Free Software Foundation, Inc.
+   Copyright (C) 1995-2001,2003,2005,2008,2010,2011
+   Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -46,7 +47,7 @@
 {
   if (!thing)
     {
-      printf("%s flunked test %d\n", it, number);
+      printf ("%s flunked test %d\n", it, number);
       ++errors;
     }
 }
@@ -55,7 +56,7 @@
 static void
 equal (const char *a, const char *b, int number)
 {
-  check(a != NULL && b != NULL && STREQ (a, b), number);
+  check (a != NULL && b != NULL && STREQ (a, b), number);
 }
 
 char one[50];
@@ -302,6 +303,48 @@
   (void) strcpy (one, "");
   (void) strcat (one, "cd");
   equal (one, "cd", 9);
+
+  int ntest = 10;
+  char buf1[80] __attribute__ ((aligned (16)));
+  char buf2[32] __attribute__ ((aligned (16)));
+  for (size_t n1 = 0; n1 < 16; ++n1)
+    for (size_t n2 = 0; n2 < 16; ++n2)
+      for (size_t n3 = 0; n3 < 32; ++n3)
+	{
+	  size_t olderrors = errors;
+
+	  memset (buf1, 'b', sizeof (buf1));
+
+	  memset (buf1 + n2, 'a', n3);
+	  buf1[n2 + n3] = '\0';
+	  strcpy (buf2 + n1, "123");
+
+	  check (strcat (buf1 + n2, buf2 + n1) == buf1 + n2, ntest);
+	  if (errors == olderrors)
+	    for (size_t i = 0; i < sizeof (buf1); ++i)
+	      {
+		if (i < n2)
+		  check (buf1[i] == 'b', ntest);
+		else if (i < n2 + n3)
+		  check (buf1[i] == 'a', ntest);
+		else if (i < n2 + n3 + 3)
+		  check (buf1[i] == "123"[i - (n2 + n3)], ntest);
+		else if (i == n2 + n3 + 3)
+		  check (buf1[i] == '\0', ntest);
+		else
+		  check (buf1[i] == 'b', ntest);
+
+		if (errors != olderrors)
+		  {
+		    printf ("n1=%zu, n2=%zu, n3=%zu, buf1=%02hhx",
+			    n1, n2, n3, buf1[0]);
+		    for (size_t j = 1; j < sizeof (buf1); ++j)
+		      printf (",%02hhx", buf1[j]);
+		    putchar_unlocked ('\n');
+		    break;
+		  }
+	      }
+	}
 }
 
 static void
@@ -347,6 +390,50 @@
 
   (void) strncat (one, "ij", (size_t)-1);	/* set sign bit in count */
   equal (one, "abcdghij", 13);
+
+  int ntest = 14;
+  char buf1[80] __attribute__ ((aligned (16)));
+  char buf2[32] __attribute__ ((aligned (16)));
+  for (size_t n1 = 0; n1 < 16; ++n1)
+    for (size_t n2 = 0; n2 < 16; ++n2)
+      for (size_t n3 = 0; n3 < 32; ++n3)
+	for (size_t n4 = 0; n4 < 16; ++n4)
+	  {
+	    size_t olderrors = errors;
+
+	    memset (buf1, 'b', sizeof (buf1));
+
+	    memset (buf1 + n2, 'a', n3);
+	    buf1[n2 + n3] = '\0';
+	    strcpy (buf2 + n1, "123");
+
+	    check (strncat (buf1 + n2, buf2 + n1, ~((size_t) 0) - n4)
+		   == buf1 + n2, ntest);
+	    if (errors == olderrors)
+	      for (size_t i = 0; i < sizeof (buf1); ++i)
+		{
+		  if (i < n2)
+		    check (buf1[i] == 'b', ntest);
+		  else if (i < n2 + n3)
+		    check (buf1[i] == 'a', ntest);
+		  else if (i < n2 + n3 + 3)
+		    check (buf1[i] == "123"[i - (n2 + n3)], ntest);
+		  else if (i == n2 + n3 + 3)
+		    check (buf1[i] == '\0', ntest);
+		  else
+		    check (buf1[i] == 'b', ntest);
+
+		  if (errors != olderrors)
+		    {
+		      printf ("n1=%zu, n2=%zu, n3=%zu, n4=%zu, buf1=%02hhx",
+			      n1, n2, n3, n4, buf1[0]);
+		      for (size_t j = 1; j < sizeof (buf1); ++j)
+			printf (",%02hhx", buf1[j]);
+		      putchar_unlocked ('\n');
+		      break;
+		    }
+		}
+	  }
 }
 
 static void

Modified: fsf/trunk/libc/sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S
==============================================================================
--- fsf/trunk/libc/sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S (original)
+++ fsf/trunk/libc/sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S Fri Jul 22 00:06:11 2011
@@ -52,51 +52,55 @@
 
 # endif
 
+	and	$63, %rcx
+	cmp	$32, %rcx
+	jbe	L(SourceStringAlignmentLess32)
+
+	and	$-16, %rsi
 	and	$15, %rcx
-	jz	L(SourceStringAlignmentZero)
-
-	and	$-16, %rsi
 	pxor	%xmm0, %xmm0
 	pxor	%xmm1, %xmm1
 
 	pcmpeqb	(%rsi), %xmm1
+	pmovmskb %xmm1, %rdx
+	shr	%cl, %rdx
+
+# ifdef USE_AS_STRNCPY
+#  if defined USE_AS_STPCPY || defined USE_AS_STRCAT
+	mov	$16, %r10
+	sub	%rcx, %r10
+	cmp	%r10, %r8
+#  else
+	mov	$17, %r10
+	sub	%rcx, %r10
+	cmp	%r10, %r8
+#  endif
+	jbe	L(CopyFrom1To16BytesTailCase2OrCase3)
+# endif
+	test	%rdx, %rdx
+	jnz	L(CopyFrom1To16BytesTail)
+
+	pcmpeqb	16(%rsi), %xmm0
+	pmovmskb %xmm0, %rdx
+
+# ifdef USE_AS_STRNCPY
+	add	$16, %r10
+	cmp	%r10, %r8
+	jbe	L(CopyFrom1To32BytesCase2OrCase3)
+# endif
+	test	%rdx, %rdx
+	jnz	L(CopyFrom1To32Bytes)
+
+	movdqu	(%rsi, %rcx), %xmm1   /* copy 16 bytes */
+	movdqu	%xmm1, (%rdi)
+
+/* If source adress alignment != destination adress alignment */
+	.p2align 4
+L(Unalign16Both):
+	sub	%rcx, %rdi
 # ifdef USE_AS_STRNCPY
 	add	%rcx, %r8
 # endif
-	pmovmskb %xmm1, %rdx
-	shr	%cl, %rdx
-# ifdef USE_AS_STRNCPY
-#  if defined USE_AS_STPCPY || defined USE_AS_STRCAT
-	cmp	$16, %r8
-#  else
-	cmp	$17, %r8
-#  endif
-	jbe	L(CopyFrom1To16BytesTailCase2OrCase3)
-# endif
-	test	%rdx, %rdx
-	jnz	L(CopyFrom1To16BytesTail)
-
-	pcmpeqb	16(%rsi), %xmm0
-	pmovmskb %xmm0, %rdx
-# ifdef USE_AS_STRNCPY
-#  if defined USE_AS_STPCPY || defined USE_AS_STRCAT
-	cmp	$32, %r8
-#  else
-	cmp	$33, %r8
-#  endif
-	jbe	L(CopyFrom1To32BytesCase2OrCase3)
-# endif
-	test	%rdx, %rdx
-	jnz	L(CopyFrom1To32Bytes)
-
-	movdqu	(%rsi, %rcx), %xmm1   /* copy 16 bytes */
-	movdqu	%xmm1, (%rdi)
-
-	sub	%rcx, %rdi
-
-/* If source adress alignment != destination adress alignment */
-	.p2align 4
-L(Unalign16Both):
 	mov	$16, %rcx
 	movdqa	(%rsi, %rcx), %xmm1
 	movaps	16(%rsi, %rcx), %xmm2
@@ -288,9 +292,10 @@
 
 /* If source adress alignment == destination adress alignment */
 
-L(SourceStringAlignmentZero):
+L(SourceStringAlignmentLess32):
 	pxor	%xmm0, %xmm0
-	movdqa	(%rsi), %xmm1
+	movdqu	(%rsi), %xmm1
+	movdqu	16(%rsi), %xmm2
 	pcmpeqb	%xmm1, %xmm0
 	pmovmskb %xmm0, %rdx
 
@@ -305,7 +310,7 @@
 	test	%rdx, %rdx
 	jnz	L(CopyFrom1To16BytesTail1)
 
-	pcmpeqb	16(%rsi), %xmm0
+	pcmpeqb	%xmm2, %xmm0
 	movdqu	%xmm1, (%rdi)
 	pmovmskb %xmm0, %rdx
 
@@ -319,6 +324,9 @@
 # endif
 	test	%rdx, %rdx
 	jnz	L(CopyFrom1To32Bytes1)
+
+	and	$-16, %rsi
+	and	$15, %rcx
 	jmp	L(Unalign16Both)
 
 /*------End of main part with loops---------------------*/
@@ -335,9 +343,6 @@
 # endif
 	.p2align 4
 L(CopyFrom1To16BytesTail):
-# if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
-	sub	%rcx, %r8
-# endif
 	add	%rcx, %rsi
 	bsf	%rdx, %rdx
 	BRANCH_TO_JMPTBL_ENTRY (L(ExitTable), %rdx, 4)
@@ -355,9 +360,6 @@
 
 	.p2align 4
 L(CopyFrom1To32Bytes):
-# if defined USE_AS_STRNCPY && !defined USE_AS_STRCAT
-	sub	%rcx, %r8
-# endif
 	bsf	%rdx, %rdx
 	add	%rcx, %rsi
 	add	$16, %rdx
@@ -465,7 +467,6 @@
 
 	.p2align 4
 L(CopyFrom1To32BytesCase2):
-	sub	%rcx, %r8
 	add	%rcx, %rsi
 	bsf	%rdx, %rdx
 	add	$16, %rdx
@@ -475,7 +476,6 @@
 	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %r8, 4)
 
 L(CopyFrom1To16BytesTailCase2):
-	sub	%rcx, %r8
 	add	%rcx, %rsi
 	bsf	%rdx, %rdx
 	cmp	%r8, %rdx
@@ -504,7 +504,6 @@
 L(CopyFrom1To32BytesCase2OrCase3):
 	test	%rdx, %rdx
 	jnz	L(CopyFrom1To32BytesCase2)
-	sub	%rcx, %r8
 	add	%rcx, %rsi
 	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %r8, 4)
 
@@ -512,7 +511,6 @@
 L(CopyFrom1To16BytesTailCase2OrCase3):
 	test	%rdx, %rdx
 	jnz	L(CopyFrom1To16BytesTailCase2)
-	sub	%rcx, %r8
 	add	%rcx, %rsi
 	BRANCH_TO_JMPTBL_ENTRY (L(ExitStrncpyTable), %r8, 4)
 

Modified: fsf/trunk/libc/sysdeps/x86_64/multiarch/strcpy-ssse3.S
==============================================================================
--- fsf/trunk/libc/sysdeps/x86_64/multiarch/strcpy-ssse3.S (original)
+++ fsf/trunk/libc/sysdeps/x86_64/multiarch/strcpy-ssse3.S Fri Jul 22 00:06:11 2011
@@ -84,10 +84,10 @@
 
 # ifdef USE_AS_STRNCPY
 	mov	%rcx, %rsi
+	sub	$16, %r8
 	and	$0xf, %rsi
 
 /* add 16 bytes rcx_shift to r8 */
-
 	add	%rsi, %r8
 # endif
 	lea	16(%rcx), %rsi
@@ -120,7 +120,7 @@
 /* rax = 0: there isn't end of string from position rsi to rsi+15 */
 
 # ifdef USE_AS_STRNCPY
-	sub	$32, %r8
+	sub	$16, %r8
 	jbe	L(CopyFrom1To16BytesCase2OrCase3)
 # endif
 	test	%rax, %rax