Re: [PATCH] regex: Add extra escapes to regular expressions in m4

Eric Blake <[email protected]>
Newsgroups gmane.comp.sysutils.autoconf.bugs,gmane.comp.lib.gnulib.bugs
Organization Red Hat, Inc.
Message-ID <[email protected]>
On 1/29/19 8:23 PM, Siddhesh Poyarekar wrote:
> On 30/01/19 2:16 AM, Eric Blake wrote:
>> Looking at m4/fnmatch.m4, it looks like we are already used to the idea
>> of doubling up \\ that will pass through AC_LANG_PROGRAM() and the
>> unquoted heredoc; on that grounds, your patch is correct.
> 
> Sorry yes, it's the shell that's eating up the backslashes; I basically
> compared the generated conftest.c and tests/test-regex.c to check if
> both programs had the same regex and they didn't.  Is it OK to commit
> this oatchpatch or would you like me to make any additional changes
> beyond changing the commit message?

A few more comments never hurt. Here's what I'll push tomorrow to
gnulib, if there are no further objections (a doc patch to autoconf is
also needed, but that will be a different reply):


From 108415713702c22a3eee10c22624c916948129bf Mon Sep 17 00:00:00 2001
From: Siddhesh Poyarekar <[email protected]>
Date: Tue, 29 Jan 2019 20:40:09 -0600
Subject: [PATCH] regex: Account for heredoc eating doubled \.

AC_LANG_PROGRAM and friends create testconf.c by using an
unquoted heredoc - but this eats any doubled \. Match what
is done in fnmatch.m4 by adding extra \ for backslashes
which must survived doubled into the resulting .c test file.
* m4/regex.m4 (gl_REGEX): Add extra escape characters to
regular expressions.
---
 ChangeLog   |  6 ++++++
 m4/regex.m4 | 12 ++++++++----
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 184908905..f28abb7d9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-01-29  Siddhesh Poyarekar  <[email protected]>
+
+	regex: Account for heredoc eating doubled \.
+	* m4/regex.m4 (gl_REGEX): Add extra escape characters to
+	regular expressions.
+
 2019-01-06  Bruno Haible  <[email protected]>

 	maintainer-makefile: Make the configure.ac section optional.
diff --git a/m4/regex.m4 b/m4/regex.m4
index 35119c5c8..24c04667e 100644
--- a/m4/regex.m4
+++ b/m4/regex.m4
@@ -1,4 +1,4 @@
-# serial 68
+# serial 69

 # Copyright (C) 1996-2001, 2003-2019 Free Software Foundation, Inc.
 #
@@ -204,7 +204,11 @@ AC_DEFUN([gl_REGEX],
                            & ~RE_CONTEXT_INVALID_DUP
                            & ~RE_NO_EMPTY_RANGES);
             memset (&regex, 0, sizeof regex);
-            s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, &regex);
+
+            /* #AC_LANG_PROGRAM uses shell heredoc, which requires
+               doubled \; we want to apply + operator to match 1-or-more
+               backslash, which requires 4 \ in a C string or 8 here */
+            s = re_compile_pattern ("[[:alnum:]_-]\\\\\\\\+$", 16, &regex);
             if (s)
               result |= 32;

@@ -217,10 +221,10 @@ AC_DEFUN([gl_REGEX],
                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.  */
+               back reference.  See above comment about doubled \. */
             re_set_syntax (RE_SYNTAX_POSIX_EGREP);
             memset (&regex, 0, sizeof regex);
-            s = re_compile_pattern ("0|()0|\\1|0", 10, &regex);
+            s = re_compile_pattern ("0|()0|\\\\1|0", 10, &regex);
             if (!s || strcmp (s, "Invalid back reference"))
               result |= 64;

-- 
2.20.1

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
signature.asc (application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEccLMIrHEYCkn0vOqp6FrSiUnQ2oFAlxRD5QACgkQp6FrSiUn
Q2oszwf9HmgSwN2gW6ygI9G/Uola9AyO8ZUlb1mqn2MZ/ZKviz7IGGJgE/KT+KD/
eDEnCd+gtTZweG+POWXAT6qaEwhYV+9ZrHxqTL9leczcmV3t1uh8lAUBzRfdTmpW
zqnccpDEtrUxQOYWgmJtcgJvAPlOfEh846lOLX5xu46Ul+Br09Dqq1PtizC3h6mk
7r0SUNFLFZWL9H0blDCued3UrT6KYNqzaFQPBaejaz+4sUw600gVFvSySzNspF2m
NiqvxUCUbdvmmMnTBnC4UAResZfum4c5fehKC0enHpOlFFC6CPfsDYISGv7RgwhM
Tg6c6tpRaN8V9vfiSPEx9Aoj3jQjMQ==
=Uqtn
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.