diff options
author | Raphael Moreira Zinsly <rzinsly@linux.ibm.com> | 2020-08-21 12:10:22 -0300 |
---|---|---|
committer | Paul E. Murphy <murphyp@linux.vnet.ibm.com> | 2020-08-26 15:56:37 -0500 |
commit | 5df6ebcf44fd89d429c1fee78c893e280a551ee8 (patch) | |
tree | af815004d5fbfb793f789d393d55404106f6bc43 /string/test-strncasecmp.c | |
parent | f032f3af2cfc4b97bde0fc61259380f83d543495 (diff) | |
download | glibc-5df6ebcf44fd89d429c1fee78c893e280a551ee8.tar glibc-5df6ebcf44fd89d429c1fee78c893e280a551ee8.tar.gz glibc-5df6ebcf44fd89d429c1fee78c893e280a551ee8.tar.bz2 glibc-5df6ebcf44fd89d429c1fee78c893e280a551ee8.zip |
string: test strncasecmp and strncpy near page boundaries
Add tests to check if strings placed at page boundaries are
handled correctly by strncasecmp and strncpy similar to tests
for strncmp and strnlen.
Diffstat (limited to 'string/test-strncasecmp.c')
-rw-r--r-- | string/test-strncasecmp.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/string/test-strncasecmp.c b/string/test-strncasecmp.c index 6a9c27beae..502222ed1d 100644 --- a/string/test-strncasecmp.c +++ b/string/test-strncasecmp.c @@ -138,6 +138,48 @@ do_test (size_t align1, size_t align2, size_t n, size_t len, int max_char, } static void +do_page_tests (void) +{ + char *s1, *s2; + int exp_result; + const size_t maxoffset = 64; + + s1 = (char *) buf1 + BUF1PAGES * page_size - maxoffset; + memset (s1, 'a', maxoffset - 1); + s1[maxoffset - 1] = '\0'; + + s2 = (char *) buf2 + page_size - maxoffset; + memset (s2, 'a', maxoffset - 1); + s2[maxoffset - 1] = '\0'; + + /* At this point s1 and s2 point to distinct memory regions containing + "aa..." with size of 63 plus '\0'. Also, 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 checks for all possible offsets up to maxoffset for both + inputs with a size larger than the string (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++) + { + exp_result = (off1 == off2) + ? 0 + : off1 < off2 + ? 'a' + : -'a'; + + FOR_EACH_IMPL (impl, 0) + check_result (impl, s1 + off1, s2 + off2, maxoffset + 1, + exp_result); + } + } +} + +static void do_random_tests (void) { size_t i, j, n, align1, align2, pos, len1, len2; @@ -334,6 +376,7 @@ test_locale (const char *locale) } do_random_tests (); + do_page_tests (); } int |