[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH 1/2] findutils/grep.c: Fix -x -v with certain pattern orders
From:       Ari Sundholm <ari () tuxera ! com>
Date:       2019-01-28 15:11:18
Message-ID: 20190128151119.14691-1-ari () tuxera ! com
[Download RAW message or body]

We found out that busybox -x -v is a bit broken:

ari@ari-thinkpad:~/busybox$ echo '  aa bb cc' | ./busybox grep -x -e 'aa.*' -e '.*bb.*'
  aa bb cc
ari@ari-thinkpad:~/busybox$ echo '  aa bb cc' | ./busybox grep -x -v -e 'aa.*' -e '.*bb.*'
ari@ari-thinkpad:~/busybox$ echo '  aa bb cc' | ./busybox grep -x -e '.*aa.*' -e 'bb.*'
  aa bb cc
ari@ari-thinkpad:~/busybox$ echo '  aa bb cc' | ./busybox grep -x -v -e '.*aa.*' -e 'bb.*'
  aa bb cc

This patch fixes the issue by making sure that the variable 'found'
never makes a transition from 1 to 0, as this would mean that
grep previously found a match on this input line.

Signed-off-by: Ari Sundholm <ari@tuxera.com>
Signed-off-by: Niko Vähäsarja <niko@tuxera.com>
---
 findutils/grep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/findutils/grep.c b/findutils/grep.c
index a4033a40b..9d9da422c 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -404,7 +404,7 @@ static int grep_file(FILE *file)
 #endif
 				) {
 					if (option_mask32 & OPT_x) {
-						found = (gl->matched_range.rm_so == 0
+						found |= (gl->matched_range.rm_so == 0
 						         && match_at[gl->matched_range.rm_eo] == '\0');
 					} else
 					if (!(option_mask32 & OPT_w)) {
-- 
2.17.1

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic