Testcase for GNU regex bugs
Gwenole Beauchesne
gbeauchesne@mandrakesoft.com
Tue Jan 14 23:06:00 GMT 2003
Hi,
The testcase in attachment, extracted from GNU grep 2.5, fails on current
glibc. i.e. with regex fixes up to 2002/12/19. Those are GNU regex bugs
when registers are used. The first test segfaults in set_regs(), the
second exhibits an infinite loop, and the third one should pass (and it
does).
Bye,
Gwenole.
-------------- next part --------------
--- glibc-2.3.1/posix/bug-regex16.c.regex-bugs 2003-01-14 23:39:00.000000000 +0100
+++ glibc-2.3.1/posix/bug-regex16.c 2003-01-14 23:45:02.000000000 +0100
@@ -0,0 +1,60 @@
+/* Test case extracted from GNU grep 2.5. */
+
+#include <sys/types.h>
+#include <mcheck.h>
+#include <regex.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static struct
+{
+ int syntax;
+ const char *pattern;
+ const char *string;
+ int start;
+} tests[] = {
+ {RE_SYNTAX_POSIX_EGREP, "^(.?)(.?)(.?)(.?)(.?)\\5\\4\\3\\2\\1$", "civic", -1},
+ {RE_SYNTAX_POSIX_EGREP, "^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?).?\\9\\8\\7\\6\\5\\4\\3\\2\\1$", "civic", 0},
+ {RE_SYNTAX_POSIX_EGREP, "^(.?)(.?)(.?)(.?)(.?).?\\5\\4\\3\\2\\1$", "civic", 0}
+};
+
+int
+main (void)
+{
+ struct re_pattern_buffer regbuf;
+ struct re_registers regs;
+ const char *err;
+ size_t i;
+ int ret = 0;
+
+ mtrace ();
+
+ for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
+ {
+ int start;
+ re_set_syntax (tests[i].syntax);
+ memset (®buf, '\0', sizeof (regbuf));
+ err = re_compile_pattern (tests[i].pattern, strlen (tests[i].pattern),
+ ®buf);
+ if (err != NULL)
+ {
+ printf ("re_compile_pattern failed: %s\n", err);
+ ret = 1;
+ continue;
+ }
+
+ start = re_search (®buf, tests[i].string, strlen (tests[i].string),
+ 0, strlen (tests[i].string), ®s);
+ if (start != tests[i].start)
+ {
+ printf ("test %d, re_search failed %d\n", i, start);
+ ret = 1;
+ regfree (®buf);
+ continue;
+ }
+ regfree (®buf);
+ }
+
+ return ret;
+}
--- glibc-2.3.1/posix/Makefile.regex-bugs 2002-12-24 01:03:09.000000000 +0100
+++ glibc-2.3.1/posix/Makefile 2003-01-14 23:40:53.000000000 +0100
@@ -75,7 +75,7 @@ tests := tstgetopt testfnm runtests run
tst-chmod bug-regex1 bug-regex2 bug-regex3 bug-regex4 \
tst-gnuglob tst-regex bug-regex5 bug-regex6 bug-regex7 \
bug-regex8 bug-regex9 bug-regex10 bug-regex11 bug-regex12 \
- bug-regex13 bug-regex14 bug-regex15
+ bug-regex13 bug-regex14 bug-regex15 bug-regex16
ifeq (yes,$(build-shared))
test-srcs := globtest
tests += wordexp-test tst-exec tst-spawn
More information about the Libc-alpha
mailing list