Bug 204255

Summary: grep -e '' does not always match in Update 4
Product: Red Hat Enterprise Linux 4 Reporter: Jordan Russell <jr-redhatbugs2>
Component: grepAssignee: Tim Waugh <twaugh>
Status: CLOSED ERRATA QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 4.4   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
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 22:44:10 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 574351    

Description Jordan Russell 2006-08-27 20:14:24 UTC
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 20:18:52 UTC
Actually, specifying "-e ''" first stops grep from highlighting the second
pattern...

I see no workaround for this ATM.

Comment 3 RHEL Program Management 2006-10-16 16:03:45 UTC
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 18:49:14 UTC
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 18:58:33 UTC
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 19:41:27 UTC
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 16:11:48 UTC
Fixed in update: grep-2.5.1-54.1.2.fc6.

Comment 13 Red Hat Bugzilla 2007-05-01 22:44:11 UTC
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