>From 4629191813aca41fa65cfba698683e662e41a5a5 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 4 Jul 2015 07:06:50 -0700 Subject: [PATCH 2/6] grep: -z '[^x]' now consistently matches newline Problem reported by Norihiro Tanaka in: http://bugs.gnu.org/20974#19 * NEWS: Document this. * src/grep.c (Gcompile, Ecompile): Clear RE_HAT_LISTS_NOT_NEWLINE. * tests/utf8-bracket: Test this. --- NEWS | 4 ++-- src/grep.c | 8 +++++--- tests/utf8-bracket | 12 +++++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 88ed0f4..35c4aad 100644 --- a/NEWS +++ b/NEWS @@ -12,8 +12,8 @@ GNU grep NEWS -*- outline -*- grep no longer reads from uninitialized memory or from beyond the end of the heap-allocated input buffer. This fix addressed CVE-2015-1345. - With -z, '.' in a pattern now consistently matches newline. - Previously, it sometimes matched newline, and sometimes did not. + With -z, '.' and '[^x]' in a pattern now consistently match newline. + Previously, they sometimes matched newline, and sometimes did not. [bug introduced in grep-2.4] When the JIT stack is exhausted, grep -P now grows the stack rather diff --git a/src/grep.c b/src/grep.c index ed54dc2..9b38cf5 100644 --- a/src/grep.c +++ b/src/grep.c @@ -1862,15 +1862,17 @@ static void Gcompile (char const *pattern, size_t size) { GEAcompile (pattern, size, - RE_SYNTAX_GREP | RE_DOT_NEWLINE | RE_NO_EMPTY_RANGES); + ((RE_SYNTAX_GREP | RE_DOT_NEWLINE | RE_NO_EMPTY_RANGES) + & ~RE_HAT_LISTS_NOT_NEWLINE)); } static void Ecompile (char const *pattern, size_t size) { GEAcompile (pattern, size, - (RE_SYNTAX_POSIX_EGREP | RE_DOT_NEWLINE - | RE_NO_EMPTY_RANGES | RE_UNMATCHED_RIGHT_PAREN_ORD)); + ((RE_SYNTAX_POSIX_EGREP | RE_DOT_NEWLINE + | RE_NO_EMPTY_RANGES | RE_UNMATCHED_RIGHT_PAREN_ORD) + & ~RE_HAT_LISTS_NOT_NEWLINE)); } static void diff --git a/tests/utf8-bracket b/tests/utf8-bracket index f5c4a60..b63afbb 100755 --- a/tests/utf8-bracket +++ b/tests/utf8-bracket @@ -24,9 +24,15 @@ printf '1\n2\n' >in || framework_failure_ fail=0 for locale in C en_US.UTF-8; do - for pattern in '1.2' '[12].2' '[1-2].2'; do - for suffix in '' '\(\)\1'; do - LC_ALL=$locale grep --null-data --quiet "$pattern$suffix" in || fail=1 + for options in -qz -qzE; do + case $options in + *E*) parens='()';; + *) parens='\(\)';; + esac + for pattern in '1.2' '[12].2' '[1-2].2' '[1-2][^a][1-2]'; do + for suffix in '' "$parens\\1"; do + LC_ALL=$locale grep $options "$pattern$suffix" in || fail=1 + done done done done -- 2.1.0