about summary refs log tree commit diff
path: root/string/test-strncpy.c
diff options
context:
space:
mode:
Diffstat (limited to 'string/test-strncpy.c')
-rw-r--r--string/test-strncpy.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/string/test-strncpy.c b/string/test-strncpy.c
index c978753ad8..e902c1764e 100644
--- a/string/test-strncpy.c
+++ b/string/test-strncpy.c
@@ -156,6 +156,40 @@ do_test (size_t align1, size_t align2, size_t len, size_t n, int max_char)
 }
 
 static void
+do_page_tests (void)
+{
+  CHAR *s1, *s2;
+  const size_t maxoffset = 64;
+
+  /* Put s1 at the maxoffset from the edge of buf1's last page.  */
+  s1 = (CHAR *) buf1 + BUF1PAGES * page_size / sizeof(CHAR) - maxoffset;
+  /* s2 needs room to put a string with size of maxoffset + 1 at s2 +
+     (maxoffset - 1).  */
+  s2 = (CHAR *) buf2 + page_size / sizeof(CHAR) - maxoffset * 2;
+
+  MEMSET (s1, 'a', maxoffset - 1);
+  s1[maxoffset - 1] = '\0';
+
+  /* Both strings are bounded to a page with read/write access and the next
+     page is protected with PROT_NONE (meaning that any access outside of the
+     page regions will trigger an invalid memory access).
+
+     The loop copies the string s1 for all possible offsets up to maxoffset
+     for both inputs with a size larger than s1 (so memory access outside the
+     expected memory regions might trigger invalid access).  */
+
+  for (size_t off1 = 0; off1 < maxoffset; off1++)
+    {
+      for (size_t off2 = 0; off2 < maxoffset; off2++)
+	{
+	  FOR_EACH_IMPL (impl, 0)
+	    do_one_test (impl, s2 + off2, s1 + off1, maxoffset - off1 - 1,
+			 maxoffset + (maxoffset - off2));
+	}
+    }
+}
+
+static void
 do_random_tests (void)
 {
   size_t i, j, n, align1, align2, len, size, mode;
@@ -317,6 +351,7 @@ test_main (void)
     }
 
   do_random_tests ();
+  do_page_tests ();
   return ret;
 }