Subject: grep bug report - improper handling of file symlinks with -r option

From: Chris Drake <[email-masked]>
Date: Thu, 8 Apr 2021 09:46:57 +1000

*This is the original working grep behaviour - it found text inside files
that were symlinks:-*
(Note the output: "*./folder/testfile1:this is my test file*")

[root@ir2 ~]# grep --version
grep (GNU grep) 2.5.1

Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@ir2 ~]# mkdir bugdemo
[root@ir2 ~]# cd bugdemo
[root@ir2 bugdemo]# echo "this is my test file" > testfile1
[root@ir2 bugdemo]# echo "this is my test file" > testfile2
[root@ir2 bugdemo]# mkdir folder
[root@ir2 bugdemo]# cd folder
[root@ir2 folder]# echo "this is my test file" > testfile3
[root@ir2 folder]# ln -s ../testfile1
[root@ir2 folder]# cd ..
[root@ir2 bugdemo]# unalias grep
[root@ir2 bugdemo]# grep -r test .
./testfile2:this is my test file
./folder/testfile1:this is my test file
./folder/testfile3:this is my test file
./testfile1:this is my test file
[root@ir2 bugdemo]#

*This is the now-broken current non-working grep behaviour - it fails to
find text inside files that were symlinks:-*
(Note the *missing* output: "*./folder/testfile1:this is my test file*")

[root@ir3 ~]# grep --version
grep (GNU grep) 3.1
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html
>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <
http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
[root@ir3 ~]# mkdir bugdemo
[root@ir3 ~]# cd bugdemo
[root@ir3 bugdemo]# echo "this is my test file" > testfile1
[root@ir3 bugdemo]# echo "this is my test file" > testfile2
[root@ir3 bugdemo]# mkdir folder
[root@ir3 bugdemo]# cd folder
[root@ir3 folder]# echo "this is my test file" > testfile3
[root@ir3 folder]# ln -s ../testfile1
[root@ir3 folder]# cd ..
[root@ir3 bugdemo]# unalias grep
[root@ir3 bugdemo]# grep -r test .
./testfile1:this is my test file
./testfile2:this is my test file
./folder/testfile3:this is my test file
[root@ir3 bugdemo]#

It looks like processing exists to not recursively follow symlinks, and
someone has messed with that which has caused files to no longer be
searched by mistake.