[PATCH] grep: fix -r following file symlinks

Sertonix sertonix at posteo.net
Mon Apr 14 10:16:06 UTC 2025


GNU grep -r doesn't search in files that are linked to by symlinks.

function                                             old     new   delta
file_action_grep                                     219     228      +9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 9/0)                 Total: 9 bytes
---
 findutils/grep.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/findutils/grep.c b/findutils/grep.c
index f6d0a73f4..0bd4898bc 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -666,6 +666,8 @@ static int FAST_FUNC file_action_grep(struct recursive_state *state UNUSED_PARAM
 	 * example will return the raw directory contents). */
 	if (S_ISLNK(statbuf->st_mode)) {
 		struct stat sb;
+		if (!(option_mask32 & OPT_R))
+			return 0;
 		if (stat(filename, &sb) != 0) {
 			if (!SUPPRESS_ERR_MSGS)
 				bb_simple_perror_msg(filename);
-- 
2.49.0



More information about the busybox mailing list