[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: Grep patch
From: "Borin, Rogerio" <rogerio.borin () avocent ! com>
Date: 2007-10-26 20:54:54
Message-ID: DCA754113E788947A6111339A04702251ABA87 () hsv-email2 ! corp ! avocent ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Hello,
I'm sending a patch to grep which was not working correctly when
multiple patterns were used.
In the main searching loop the program read a line of text and then in
an inner loop it tried to match against each of the patterns. However,
if a match were found it didn't stop the inner loop, in a way that only
the last pattern was honored. The patched just added a 'break' to this
loop.
The bug was only visible when using -F flag (literal matching) because
the variable 'ret' was never reset when this flag was not passed (normal
regexp matching).
In order to experience the bug, try 'grep -F -e "txt1" -e "txt2"
input.txt', where input.txt is:
--------
txt1
txt2
--------
The output will be 'txt2' only.
Regards,
Rogerio
[Attachment #5 (text/html)]
<html xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:Arial;}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:Arial;
color:windowtext;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 face=Arial><span \
style='font-size:10.0pt'>Hello,<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span \
style='font-size:10.0pt'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'>I’m
sending a patch to grep which was not working correctly when multiple patterns
were used.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'>In
the main searching loop the program read a line of text and then in an inner
loop it tried to match against each of the patterns. However, if a match were found
it didn’t stop the inner loop, in a way that only the last pattern was
honored. The patched just added a ‘break’ to this \
loop.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span \
style='font-size:10.0pt'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'>The
bug was only visible when using –F flag (literal matching) because the
variable ‘ret’ was never reset when this flag was not passed
(normal regexp matching).<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span \
style='font-size:10.0pt'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'>In
order to experience the bug, try ‘grep –F –e “txt1”
–e “txt2” input.txt’, where input.txt \
is:<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span \
style='font-size:10.0pt'>--------<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span \
style='font-size:10.0pt'>txt1<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span \
style='font-size:10.0pt'>txt2<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span \
style='font-size:10.0pt'>--------<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt'>The
output will be ‘txt2’ only.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span \
style='font-size:10.0pt'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span \
style='font-size:10.0pt'>Regards,<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span \
style='font-size:10.0pt'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span \
style='font-size:10.0pt'>Rogerio<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span \
style='font-size:10.0pt'><o:p> </o:p></span></font></p>
</div>
</body>
</html>
["grep.patch" (application/octet-stream)]
--- busybox-1.7.1/findutils/grep.c 2007-10-26 18:29:01.000000000 -0200
+++ busybox-1.7.1-grep/findutils/grep.c 2007-10-26 18:29:09.000000000 -0200
@@ -162,9 +162,11 @@
gl = (grep_list_data_t *)pattern_ptr->data;
if (FGREP_FLAG) {
ret = strstr(line, gl->pattern) != NULL;
+ if (ret)
+ break;
} else {
/*
- * test for a postitive-assertion match (regexec returns success (0)
+ * test for a positive-assertion match (regexec returns success (0)
* and the user did not specify invert search), or a negative-assertion
* match (regexec returns failure (REG_NOMATCH) and the user specified
* invert search)
@@ -176,16 +178,19 @@
regmatch.rm_so = 0;
regmatch.rm_eo = 0;
if (regexec(&(gl->preg), line, 1, ®match, 0) == 0) {
- if (!(option_mask32 & OPT_w))
+ if (!(option_mask32 & OPT_w)) {
ret = 1;
- else {
+ break;
+ } else {
char c = ' ';
if (regmatch.rm_so)
c = line[regmatch.rm_so - 1];
if (!isalnum(c) && c != '_') {
c = line[regmatch.rm_eo];
- if (!c || (!isalnum(c) && c != '_'))
+ if (!c || (!isalnum(c) && c != '_')) {
ret = 1;
+ break;
+ }
}
}
}
_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic