]> Savannah Git Hosting - gnulib.git/commitdiff
regex: work around a bug in glibc-2.27 and prior
authorJim Meyering <meyering@fb.com>
Sat, 15 Dec 2018 23:24:21 +0000 (15:24 -0800)
committerJim Meyering <meyering@fb.com>
Sat, 15 Dec 2018 23:28:10 +0000 (15:28 -0800)
* m4/regex.m4 (gl_REGEX): Reject any system regexp that gets a failed
assertion for /0|()0|\1|0/.
* tests/test-regex.c (main): Add the same test here.

ChangeLog
m4/regex.m4
tests/test-regex.c

index 35c54129bffb5b3f124fae56e2cbb4809a03ba38..e86bbd6cfa8a18de8790044aaf4e2dd05333fb2e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-12-15  Jim Meyering  <meyering@fb.com>
+
+       regex: work around a bug in glibc-2.27 and prior
+       * m4/regex.m4 (gl_REGEX): Reject any system regexp that gets a failed
+       assertion for /0|()0|\1|0/.
+       * tests/test-regex.c (main): Add the same test here.
+
 2018-12-15  Bruno Haible  <bruno@clisp.org>
 
        localename: Fix use of uninitialized shell variable.
index 055d71b5aaa46c1b173aa4713999795e57f69343..e3c63e7cbe1f092fb0b4b3b04c465c9a0f2dffa4 100644 (file)
@@ -1,4 +1,4 @@
-# serial 67
+# serial 68
 
 # Copyright (C) 1996-2001, 2003-2018 Free Software Foundation, Inc.
 #
@@ -213,6 +213,17 @@ AC_DEFUN([gl_REGEX],
             if (! REG_STARTEND)
               result |= 64;
 
+            /* Matching with the compiled form of this regexp would provoke
+              an assertion failure prior to glibc-2.28:
+                regexec.c:1375: pop_fail_stack: Assertion 'num >= 0' failed
+              With glibc-2.28, compilation fails and reports the invalid
+              back reference.  */
+            re_set_syntax (RE_SYNTAX_POSIX_EGREP);
+            memset (&regex, 0, sizeof regex);
+            s = re_compile_pattern ("0|()0|\\1|0", 10, &regex);
+            if (!s || strcmp (s, "Invalid back reference"))
+              result |= 64;
+
 #if 0
             /* It would be nice to reject hosts whose regoff_t values are too
                narrow (including glibc on hosts with 64-bit ptrdiff_t and
index 0a009b896cf5f879d73cd7c847d5f29d0fbcdfa7..a0aa1123be4881ca0063d7c9b04ed1a6c4c38799 100644 (file)
@@ -237,6 +237,17 @@ main (void)
   if (! REG_STARTEND)
     result |= 64;
 
+  /* Matching with the compiled form of this regexp would provoke
+     an assertion failure prior to glibc-2.28:
+       regexec.c:1375: pop_fail_stack: Assertion 'num >= 0' failed
+     With glibc-2.28, compilation fails and reports the invalid
+     back reference.  */
+  re_set_syntax (RE_SYNTAX_POSIX_EGREP);
+  memset (&regex, 0, sizeof regex);
+  s = re_compile_pattern ("0|()0|\\1|0", 10, &regex);
+  if (!s || strcmp (s, "Invalid back reference"))
+    result |= 64;
+
 #if 0
   /* It would be nice to reject hosts whose regoff_t values are too
      narrow (including glibc on hosts with 64-bit ptrdiff_t and