From: Jim Meyering Date: Sat, 15 Dec 2018 23:24:21 +0000 (-0800) Subject: regex: work around a bug in glibc-2.27 and prior X-Git-Tag: v1.0~5234 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=55a4abd92a0a8fa0a9d9aff3892505f7b0c6d73c;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 35c54129bf..e86bbd6cfa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2018-12-15 Jim Meyering + + 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 localename: Fix use of uninitialized shell variable. diff --git a/m4/regex.m4 b/m4/regex.m4 index 055d71b5aa..e3c63e7cbe 100644 --- a/m4/regex.m4 +++ b/m4/regex.m4 @@ -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 (®ex, 0, sizeof regex); + s = re_compile_pattern ("0|()0|\\1|0", 10, ®ex); + 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 diff --git a/tests/test-regex.c b/tests/test-regex.c index 0a009b896c..a0aa1123be 100644 --- a/tests/test-regex.c +++ b/tests/test-regex.c @@ -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 (®ex, 0, sizeof regex); + s = re_compile_pattern ("0|()0|\\1|0", 10, ®ex); + 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