Bug 204255 - grep -e '' does not always match in Update 4
grep -e '' does not always match in Update 4
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: grep (Show other bugs)
4.4
All Linux
medium Severity medium
: ---
: ---
Assigned To: Tim Waugh
:
Depends On:
Blocks: 574351
  Show dependency treegraph
 
Reported: 2006-08-27 16:14 EDT by Jordan Russell
Modified: 2010-03-17 06:32 EDT (History)
0 users

See Also:
Fixed In Version: RHBA-2007-0281
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 574351 (view as bug list)
Environment:
Last Closed: 2007-05-01 18:44:10 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Jordan Russell 2006-08-27 16:14:24 EDT
Description of problem:
After upgrading to Update 4 I've found that passing "-e ''" to grep no longer
matches every line unless it's specified as the first pattern.

Older grep packages didn't have this problem. Nor does Fedora Core 5.

Version-Release number of selected component (if applicable):
grep-2.5.1-32.2

How reproducible:
Always

Steps to Reproduce:
These *should* produce the same output.

echo test | grep --color=always -e 'HighlightThis' -e ''
echo test | grep --color=always -e '' -e 'HighlightThis'

"-e 'HighlightThis'" should make it highlight all occurrences of
"HighlightThis", and "-e ''" should make it print non-matching lines as well.


Actual results:
# echo test | grep --color=always -e 'HighlightThis' -e ''
# echo test | grep --color=always -e '' -e 'HighlightThis'
test

Expected results:
# echo test | grep --color=always -e 'HighlightThis' -e ''
test
# echo test | grep --color=always -e '' -e 'HighlightThis'
test
Comment 1 Jordan Russell 2006-08-27 16:18:52 EDT
Actually, specifying "-e ''" first stops grep from highlighting the second
pattern...

I see no workaround for this ATM.
Comment 3 RHEL Product and Program Management 2006-10-16 12:03:45 EDT
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux maintenance release.  Product Management has requested
further review of this request by Red Hat Engineering, for potential
inclusion in a Red Hat Enterprise Linux Update release for currently deployed
products.  This request is not yet committed for inclusion in an Update
release.
Comment 5 Tim Waugh 2006-11-22 13:49:14 EST
Work-around is to convert to non-UTF8 input charset and set LC_ALL.  e.g.
LC_ALL=en_GB grep ... seems to avoid the problem whereas LC_ALL=en_GB.UTF-8
exhibits the bug.

Investigating.
Comment 6 Tim Waugh 2006-11-22 13:58:33 EST
Actually an easier work-around is this:

grep -e 'HighlightThis' -e '' -e ''

This is a Gcompile bug, and it exists in unpatched grep-2.5.1a.
Comment 7 Tim Waugh 2006-11-22 14:41:27 EST
Fix is:

--- grep-2.5.1a/src/grep.c.empty-pattern        2006-11-22 19:05:43.000000000 +0000
+++ grep-2.5.1a/src/grep.c      2006-11-22 19:22:04.000000000 +0000
@@ -1667,9 +1667,6 @@
          out_invert ^= 1;
          match_lines = match_words = 0;
        }
-      else
-       /* Strip trailing newline. */
-        --keycc;
     }
   else
     if (optind < argc)
--- grep-2.5.1a/src/search.c.empty-pattern      2006-11-22 19:21:11.000000000 +0000
+++ grep-2.5.1a/src/search.c    2006-11-22 19:35:06.000000000 +0000
@@ -204,6 +204,10 @@
       motif = sep;
     } while (sep && total != 0);
 
+  /* Strip trailing newline. */
+  if (size && pattern[size - 1] == '\n')
+    size--;
+
   /* In the match_words and match_lines cases, we use a different pattern
      for the DFA matcher that will quickly throw out cases that won't work.
      Then if DFA succeeds we do some hairy stuff using the regex matcher
@@ -288,6 +292,10 @@
       motif = sep;
     } while (sep && total != 0);
 
+  /* Strip trailing newline. */
+  if (size && pattern[size - 1] == '\n')
+    size--;
+
   /* In the match_words and match_lines cases, we use a different pattern
      for the DFA matcher that will quickly throw out cases that won't work.
      Then if DFA succeeds we do some hairy stuff using the regex matcher
Comment 12 Fedora Update System 2006-12-12 11:11:48 EST
Fixed in update: grep-2.5.1-54.1.2.fc6.
Comment 13 Red Hat Bugzilla 2007-05-01 18:44:11 EDT
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2007-0281.html

Note You need to log in before you can comment on or make changes to this bug.