Bug 204255 - grep -e '' does not always match in Update 4
Summary: grep -e '' does not always match in Update 4
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: grep
Version: 4.4
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
: ---
Assignee: Tim Waugh
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks: 574351
TreeView+ depends on / blocked
 
Reported: 2006-08-27 20:14 UTC by Jordan Russell
Modified: 2010-03-17 10:32 UTC (History)
0 users

Fixed In Version: RHBA-2007-0281
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 574351 (view as bug list)
Environment:
Last Closed: 2007-05-01 22:44:10 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2007:0281 0 normal SHIPPED_LIVE grep bug fix update 2007-04-28 18:38:28 UTC

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



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