Bug 1178305

Summary: grep -d recurse doesn't check if input is a directory
Product: [Fedora] Fedora Reporter: Andrew Hecox <ahecox>
Component: grepAssignee: Jaroslav Škarvada <jskarvad>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 21CC: ahecox, jskarvad, lkundrak
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: grep-2.21-5.fc22 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-04-11 09:08:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Andrew Hecox 2015-01-03 19:23:51 UTC
if grep is handed an pipe on standard in, it is not correctly checking if it's a directory before acting on the '-d recurse' option. 

from grep man page:

-d ACTION, --directories=ACTION
              If an input file is a directory, use ACTION to process it.  By default, ACTION is read, i.e., read directories just as if they were ordinary files.  If ACTION is skip, silently skip directories.  If ACTION is  recurse, 
read all files under each directory, recursively, following symbolic links only if they are on the command line.  This is equivalent to the -r option.

behavior in Fedora 21:

ahecox@localhost ~ $ which grep
/bin/grep

ahecox@localhost ~ $ grep -V
grep (GNU grep) 2.21
Copyright (C) 2014 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>.

ahecox@localhost ~ $ file foo
foo: cannot open `foo' (No such file or directory)

ahecox@localhost ~ $ echo foo | grep foo
foo

ahecox@localhost ~ $ echo foo | grep -d recurse foo
rpm-qa:foomatic-db-ppds-4.0-44.20140707.fc21.noarch
rpm-qa:foomatic-4.0.11-6.fc21.x86_64
rpm-qa:foomatic-db-filesystem-4.0-44.20140707.fc21.noarch
rpm-qa:foomatic-db-4.0-44.20140707.fc21.noarch
.svn/pristine/89/893e400d588348f701bcbaf75e4a15903c40d4db.svn-base:#usage() { pusage: "foo"; }
... (many, many lines clipped, recursing starting in the CWD)

previous versions behaved inline with the description of the man page (checking that the input is a directory before following the action). The latest test box I have is RHEL 6 (grep version 2.6.3) so not sure that this is a recent change.

Let me know if I can help test or answer questions.

Comment 1 Jaroslav Škarvada 2015-01-22 09:40:50 UTC
Could you provide reproducer? I.e. actions taken, expected result, current result? Thanks.

Comment 2 Andrew Hecox 2015-04-04 18:55:54 UTC
(In reply to Jaroslav Škarvada from comment #1)
> Could you provide reproducer? I.e. actions taken, expected result, current
> result? Thanks.

hi Jaroslav,

I provided steps in the description, please let me know what is unclear. -d recurse should only recurse if the input arguments are directories. In the reproducer the input in stdin.

Let me know if that makes sense, thanks!

Comment 3 Jaroslav Škarvada 2015-04-07 09:04:52 UTC
This seems to be wanted behaviour, upstream commit fixing the docs:
http://git.savannah.gnu.org/cgit/grep.git/commit/?id=c8b9364d5900a40809827aee6cc53705073278f6

So I will also fix the docs.

Comment 4 Fedora Update System 2015-04-07 09:29:21 UTC
grep-2.21-5.fc22 has been submitted as an update for Fedora 22.
https://admin.fedoraproject.org/updates/grep-2.21-5.fc22

Comment 5 Fedora Update System 2015-04-07 09:30:04 UTC
grep-2.21-3.fc21 has been submitted as an update for Fedora 21.
https://admin.fedoraproject.org/updates/grep-2.21-3.fc21

Comment 6 Fedora Update System 2015-04-07 17:09:37 UTC
Package grep-2.21-5.fc22:
* should fix your issue,
* was pushed to the Fedora 22 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing grep-2.21-5.fc22'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2015-5677/grep-2.21-5.fc22
then log in and leave karma (feedback).

Comment 7 Fedora Update System 2015-04-11 09:08:24 UTC
grep-2.21-3.fc21 has been pushed to the Fedora 21 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 8 Andrew Hecox 2015-04-12 18:13:45 UTC
Thanks Jaroslav

Comment 9 Fedora Update System 2015-04-21 19:17:18 UTC
grep-2.21-5.fc22 has been pushed to the Fedora 22 stable repository.  If problems still persist, please make note of it in this bug report.