bug-grep
[Top][All Lists]
Advanced

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

[bug-grep] Re: Certain use of grep -P causes seg fault


From: Claudio Fontana
Subject: [bug-grep] Re: Certain use of grep -P causes seg fault
Date: Sat, 19 Feb 2005 11:56:54 +0100 (CET)

 --- address@hidden wrote: 
> Hello, I'm not sure if this is a problem with grep
> or with the pcre 
> library that it's calling.
> 
> $ echo a|grep -P '\w\s'
> Segmentation fault

Hello,
I am very new to grep source, however I might ease the
burden for the more seasoned grep people here by
providing a starting point.

I've traced the problem to the call to memchr(3) in
search.c at line 769 where it reads:

      if (!exact)
        {
          end = memchr (end, eol, buflim - end);
          end++;
          while (buf < beg && beg[-1] != eol)
            --beg;
        }

The call to memchr assumes that eol is found, however
it is not, because end points to the end of the
string. I imagine that this happens because the last
\n is actually part of the match (the \s part in
'\w\s'), so the pointer is set after the match, where
only a \0 remains and no more \n.

My quick solution would be:

--- search.c.~1.31.~    2004-12-16 09:19:29.000000000
+0100
+++ search.c    2005-02-19 11:29:06.000000000 +0100
@@ -768,8 +768,10 @@
       char eol = eolbyte;
       if (!exact)
        {
-         end = memchr (end, eol, buflim - end);
-         end++;
+         if (!(end = memchr (end, eol, buflim -
end)))
+           end = buflim;
+         else
+           end++;
          while (buf < beg && beg[-1] != eol)
            --beg;
        }

however I saw that the same code pattern with memchr
and end++ is present in other places in search.c so
this change, although it COULD solve the thing at hand
might not be the optimal solution. I'm sure the right
people will correct me.

Claudio




                
___________________________________ 
Nuovo Yahoo! Messenger: E' molto più divertente: Audibles, Avatar, Webcam, 
Giochi, Rubrica… Scaricalo ora! 
http://it.messenger.yahoo.it




reply via email to

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