Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 195901 - grep from sys-apps/grep-2.5.1a-r1 and older hangs forever on some conditions (+patch)
Summary: grep from sys-apps/grep-2.5.1a-r1 and older hangs forever on some conditions ...
Status: RESOLVED DUPLICATE of bug 171776
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All All
: High normal (vote)
Assignee: Gentoo Linux bug wranglers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-14 23:34 UTC by spiritus
Modified: 2007-10-16 18:24 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
grep-2.5.1a_colorize_fix.patch (grep-2.5.1a_colorize_fix.patch,649 bytes, patch)
2007-10-14 23:35 UTC, spiritus
Details | Diff
grep-2.5.1a-r2.ebuild (grep-2.5.1a-r2.ebuild,1.99 KB, patch)
2007-10-14 23:55 UTC, spiritus
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description spiritus 2007-10-14 23:34:11 UTC
I have accidently found, that there is a problem with grep 2.5.1a and early versions having --colour support. It hangs on the following test case: 
echo test|grep --colour=yes -i ".*".

It loops forever in the while-loop at grep-2.5.1a/src/grep.c beginning from line 570: 

while ((match_offset = (*execute) (ibeg, ilim-ibeg, &match_size, 1)) 
!= (size_t) -1) 
{ 
char const *b = beg + match_offset; 
if (b == lim) 
break; 
fwrite (beg, sizeof (char), match_offset, stdout); 
printf ("\33[%sm", grep_color); 
fwrite (b, sizeof (char), match_size, stdout); 
fputs ("\33[00m", stdout); 
beg = b + match_size; 
ibeg = ibeg + match_offset + match_size; 
} 

gdb show that match_offset=0, so b = beg and it and it loops forever, because match_offset != -1 and b != lim. 
It seems there is a fix for the same problem, but for different situation when (match_icase==0) i.e. grep --colour without switch "-i". 
Suggested patch attached. 

Tested with the most recent stable sys-apps/grep-2.5.1a-r1 with the default setting: alias grep='grep --colour=auto'.

My original bugreport here: https://savannah.gnu.org/bugs/?21342


Reproducible: Always

Steps to Reproduce:
echo test|grep --colour=yes -i ".*".
Actual Results:  
grep hangs 

Expected Results:  
Normal exit
Comment 1 spiritus 2007-10-14 23:35:38 UTC
Created attachment 133477 [details, diff]
grep-2.5.1a_colorize_fix.patch
Comment 2 spiritus 2007-10-14 23:55:21 UTC
Created attachment 133481 [details, diff]
grep-2.5.1a-r2.ebuild
Comment 3 Jakub Moc (RETIRED) gentoo-dev 2007-10-15 06:54:53 UTC

*** This bug has been marked as a duplicate of bug 171776 ***
Comment 4 spiritus 2007-10-15 22:16:29 UTC
There is no solution for the bug. grep 2.5.3 is buggy.

$ grep -B1 ^KEYWORDS /usr/portage/sys-apps/grep/grep-2.5.3.ebuild
# too many test failures -- once those get fixed, we'll ~arch
KEYWORDS="" #~alpha ~amd64 ~arm ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~sparc-fbsd ~x86 ~x86-fbsd"
Comment 5 spiritus 2007-10-15 22:18:09 UTC
How about getting my fix for current stable grep 2.5.1a?
Comment 6 Jakub Moc (RETIRED) gentoo-dev 2007-10-16 05:17:37 UTC
(In reply to comment #4)
> grep 2.5.3 is buggy.

We know that it's buggy. 

*** This bug has been marked as a duplicate of bug 171776 ***
Comment 7 spiritus 2007-10-16 18:24:18 UTC
Please, clarify. There is no solution for the bug because 2.5.3 is hardmasked and 2.5.1a has the bug. Why don't just fix it  with my patch https://bugs.gentoo.org/attachment.cgi?id=133477? :(