changeset 40029:6160efb8efef

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.
author Jim Meyering <meyering@fb.com>
date Sat, 15 Dec 2018 15:24:21 -0800
parents 8850daca13bd
children 41dc174470c2
files ChangeLog m4/regex.m4 tests/test-regex.c
diffstat 3 files changed, 30 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Dec 15 23:27:49 2018 +0100
+++ b/ChangeLog	Sat Dec 15 15:24:21 2018 -0800
@@ -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.
--- a/m4/regex.m4	Sat Dec 15 23:27:49 2018 +0100
+++ b/m4/regex.m4	Sat Dec 15 15:24:21 2018 -0800
@@ -1,4 +1,4 @@
-# serial 67
+# serial 68
 
 # Copyright (C) 1996-2001, 2003-2018 Free Software Foundation, Inc.
 #
@@ -213,6 +213,17 @@
             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
--- a/tests/test-regex.c	Sat Dec 15 23:27:49 2018 +0100
+++ b/tests/test-regex.c	Sat Dec 15 15:24:21 2018 -0800
@@ -237,6 +237,17 @@
   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