This fixes a bug introduced by commit 414db791d0dc79905e5afe20e503941b8f9778cc
where busybox would hang on grep -w ^ file.txt. Busybox will now produce
output compatible with upstream grep in this case.

Signed-off-by: Bartosz Golaszewski <[email protected]>
---
 findutils/grep.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/findutils/grep.c b/findutils/grep.c
index b8ad1bf..acf38bb 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -416,8 +416,14 @@ static int grep_file(FILE *file)
                                                        if (!c || (!isalnum(c) 
&& c != '_')) {
                                                                found = 1;
                                                        } else {
-                                                               match_at += 
gl->matched_range.rm_eo;
-                                                               goto 
opt_w_again;
+                                                               /* Avoid an 
infinite loop if the partially
+                                                                * matched 
string is 0 bytes long - e.g. "^" regex
+                                                                * passed as 
search pattern.
+                                                                */
+                                                               if 
(gl->matched_range.rm_eo) {
+                                                                       
match_at += gl->matched_range.rm_eo;
+                                                                       goto 
opt_w_again;
+                                                               }
                                                        }
                                                }
                                        }
-- 
1.7.10.4

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to