[Bug 247126] [PATCH] zgrep(1) does not handle -f FILE correctly
bugzilla-noreply at freebsd.org
bugzilla-noreply at freebsd.org
Tue Jun 9 21:53:08 UTC 2020
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=247126
Bug ID: 247126
Summary: [PATCH] zgrep(1) does not handle -f FILE correctly
Product: Base System
Version: 12.1-RELEASE
Hardware: Any
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: bin
Assignee: bugs at FreeBSD.org
Reporter: leres at freebsd.org
Somewhere between FreeBSD 11 and 12, zfgrep and friends became a wrapper shell
script. We've found that it does not handle the -f flag correctly:
# Works
% zfgrep RELEASE /etc/motd
FreeBSD 12.1-RELEASE-p3 GENERIC
# Hangs reading from stdin
% echo RELEASE > /tmp/0
% zfgrep -f /tmp/0 /etc/motd
/etc/motd:FreeBSD 12.1-RELEASE-p3 GENERIC
^Z
Suspended
leviathan 89 % ps t
PID TT STAT TIME COMMAND
11249 4 Ss 0:00.11 -csh (csh)
12190 4 T 0:00.00 /bin/sh /usr/bin/zfgrep -f /tmp/0 /etc/motd
12191 4 T 0:00.00 /usr/bin/zcat -f -
12192 4 T 0:00.00 grep -F -f /tmp/0 -- /etc/motd -
12193 4 R+ 0:00.00 ps t
The problem is when -f is used there is no command line pattern and the wrapper
script incorrectly uses the first non-flag argument as a pattern and
incorrectly decides we want to read from stdin. Meanwhile grep is invoked with
the pattern (really the target file) and a '-'. In then outputs any matches and
hangs, reading from stdin.
Here's the most minimal patch I could develop in two minutes.
--
You are receiving this mail because:
You are the assignee for the bug.
More information about the freebsd-bugs
mailing list