public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Check that strnlen won't go beyond the maximum length
@ 2021-03-27 16:24 H.J. Lu
  2021-03-27 17:51 ` Florian Weimer
  0 siblings, 1 reply; 5+ messages in thread
From: H.J. Lu @ 2021-03-27 16:24 UTC (permalink / raw)
  To: libc-alpha

Run strnlen tests on strings without the null byte around the page
boundary.
---
 string/test-strnlen.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/string/test-strnlen.c b/string/test-strnlen.c
index 61eb521dc1..a49d93afa2 100644
--- a/string/test-strnlen.c
+++ b/string/test-strnlen.c
@@ -196,6 +196,31 @@ do_page_tests (void)
     }
 }
 
+/* Tests meant to unveil fail on implementation that does not access bytes
+   without the null character around the page boundary accordingly.  */
+static void
+do_page_2_tests (void)
+{
+  size_t i, exp_len, offset;
+  size_t last_offset = page_size / sizeof (CHAR);
+
+  CHAR *s = (CHAR *) buf2;
+  memset (s, 65, page_size);
+
+  /* Place short strings ending at page boundary.  */
+  offset = last_offset;
+  for (i = 0; i < 128; i++)
+    {
+      /* Decrease offset to stress several sizes and alignments.  */
+      offset--;
+      exp_len = last_offset - offset;
+      FOR_EACH_IMPL (impl, 0)
+        {
+          do_one_test (impl, (CHAR *) (s + offset), exp_len, exp_len);
+        }
+    }
+}
+
 int
 test_main (void)
 {
@@ -242,6 +267,7 @@ test_main (void)
 
   do_random_tests ();
   do_page_tests ();
+  do_page_2_tests ();
   return ret;
 }
 
-- 
2.30.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-01-27 17:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-27 16:24 [PATCH] Check that strnlen won't go beyond the maximum length H.J. Lu
2021-03-27 17:51 ` Florian Weimer
2021-03-27 18:09   ` [PATCH v2] test-strnlen.c: " H.J. Lu
2021-03-27 18:34     ` Florian Weimer
2022-01-27 17:09       ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).