bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-grep] segfaults with -m1 -A99


From: Claudio Fontana
Subject: Re: [bug-grep] segfaults with -m1 -A99
Date: Wed, 16 Mar 2005 04:29:57 +0100 (CET)

Hello,

I have reproduced the problem with current CVS
version, and it is indeed a grep bug.

I include a dirty workaround that fixes your issue
"downstream", however the real place to fix is
somewhere else, since sentinels do not work as they
should.

Get latest grep source, then apply patch against
src/search.c using

patch search.c < search.c.workaround.patch

Then rebuild.
All this IMO. Maybe someone more experienced with grep
will give you better advice.

Claudio

--- Pavol Gono <address@hidden> wrote:
> Hi
> 
> I noticed segfaults while using egrep with
> parameters
> --max-count and --after-context. Maybe I use wrong
> combination
> of parameters, but I didn't find workaround. Or
> something else
> is wrong?
> 
> $ cat bla1
> 4
> 40
> $ cat bla2
> 4
> 04
> $ cat bla3
> 4
> 444
> $ egrep -m1 -A99 "^4$" bla1
> 4
> Segmentation fault
> $ egrep -m1 -A99 "^4$" bla2
> 4
> Segmentation fault
> $ egrep -m1 -A99 "^4$" bla3
> 4
> Segmentation fault
> $ egrep -m1 -A99 "^4" bla1
> 4
> $ egrep -m1 -A99 "^4" bla2
> 4
> Segmentation fault
> $ egrep -m1 -A99 "^4" bla3
> 4
> $ egrep -m1 -A99 "4$" bla1
> 4
> Segmentation fault
> $ egrep -m1 -A99 "4$" bla2
> 4
> $ egrep -m1 -A99 "4$" bla3
> 4
> 
> 
> The same for grep.
> Tested with grep-2.5.1-302 on Suse and grep
> 2.5.1.ds1-4 on
> Debian. On machine with 1GB RAM I saw message "grep:
> Memory
> exhausted" instead of segfaults.
> 
> Pavol



                
___________________________________ 
Nuovo Yahoo! Messenger: E' molto più divertente: Audibles, Avatar, Webcam, 
Giochi, Rubrica… Scaricalo ora! 
http://it.messenger.yahoo.it
--- ../../grep/src/search.c     2005-03-09 14:11:28.000000000 +0100
+++ ./search.c  2005-03-16 04:15:34.000000000 +0100
@@ -383,7 +383,8 @@
              beg += offset;
              /* Narrow down to the line containing the candidate, and
                 run it through DFA. */
-             end = memchr(beg, eol, buflim - beg);
+             if (!(end = memchr(beg, eol, buflim - beg)))
+               end = buflim;
              end++;
 #ifdef MBS_SUPPORT
              if (MB_CUR_MAX > 1 && mb_properties[beg - buf] == 0)
@@ -404,7 +405,8 @@
                break;
              /* Narrow down to the line we've found. */
              beg += offset;
-             end = memchr (beg, eol, buflim - beg);
+             if (!(end = memchr (beg, eol, buflim - beg)))
+               end = buflim;
              end++;
              while (beg > buf && beg[-1] != eol)
                --beg;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]