summaryrefslogtreecommitdiff
path: root/tests/test-strstr.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2010-10-05 16:39:32 -0600
committerEric Blake <eblake@redhat.com>2010-10-05 16:59:37 -0600
commitc823199df2cc03b6bd70d0a2fef5999af82792fe (patch)
treee333591d48eafa6ce7f00cc046fe4e7363e8f957 /tests/test-strstr.c
parent4a8bddf9e13915227bba4088b80d7f058688ff5f (diff)
downloadgnulib-c823199df2cc03b6bd70d0a2fef5999af82792fe.tar.gz
memmem, strstr, strcasestr: fix bug with long periodic needle
* lib/str-two-way.h (two_way_long_needle): Avoid bug with long periodic needle having false positive. * m4/memmem.m4 (gl_FUNC_MEMMEM_SIMPLE): Detect bug in glibc 2.12 and cygwin 1.7.7. (gl_FUNC_MEMMEM): Be more pessimistic when cross-compiling. * m4/strcasestr.m4 (gl_FUNC_STRCASESTR_SIMPLE) (gl_FUNC_STRCASESTR): Likewise. * m4/strstr.m4 (gl_FUNC_STRSTR_SIMPLE, gl_FUNC_STRSTR): Likewise. * tests/test-memmem.c (main): Expose the bug. * tests/test-strcasestr.c (main): Likewise. * tests/test-strstr.c (main): Likewise. * tests/test-c-strcasestr.c (main): Likewise. * doc/glibc-functions/memmem.texi (memmem): Document the bug. * doc/posix-functions/strstr.texi (strstr): Likewise. * doc/glibc-functions/strcasestr.texi (strcasestr): Likewise. Reported via http://sourceware.org/bugzilla/show_bug.cgi?id=12092 Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'tests/test-strstr.c')
-rw-r--r--tests/test-strstr.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/test-strstr.c b/tests/test-strstr.c
index 1482e7de82..1ddd015276 100644
--- a/tests/test-strstr.c
+++ b/tests/test-strstr.c
@@ -91,6 +91,25 @@ main (int argc, char *argv[])
ASSERT (result == input + 11);
}
+ /* Check that a long periodic needle does not cause false positives. */
+ {
+ const char input[] = ("F_BD_CE_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD"
+ "_C3_88_20_EF_BF_BD_EF_BF_BD_EF_BF_BD"
+ "_C3_A7_20_EF_BF_BD");
+ const char need[] = "_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD";
+ const char *result = strstr (input, need);
+ ASSERT (result == NULL);
+ }
+ {
+ const char input[] = ("F_BD_CE_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD"
+ "_C3_88_20_EF_BF_BD_EF_BF_BD_EF_BF_BD"
+ "_C3_A7_20_EF_BF_BD_DA_B5_C2_A6_20"
+ "_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD");
+ const char need[] = "_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD";
+ const char *result = strstr (input, need);
+ ASSERT (result == input + 115);
+ }
+
/* Check that a very long haystack is handled quickly if the needle is
short and occurs near the beginning. */
{