Bug 180937 - fgrep(1) stalls when a file contains null character
Summary: fgrep(1) stalls when a file contains null character
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 9.1-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-30 07:50 UTC by y
Modified: 2020-12-08 14:05 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description y 2013-07-30 07:50:00 UTC
"fgrep -i numeric_or_symbol" or "grep -F -i numeric_or_symbol" stalls
when a file contains null character.

"fgrep -i alphabet_only" does not stall.
fgrep without -i does not.
grep, egrep and original GNU fgrep (ports/textproc/gnugrep) does not.

How-To-Repeat: dd if=/dev/zero bs=1 count=1 | fgrep -i 1
Comment 1 dt71 2014-12-06 22:47:06 UTC
Can't reproduce on 10.1-RELEASE.

The only weirdness I see is the following:
$ dd if=/dev/zero bs=1 count=1 2>/dev/null | bsdgrep -i .
$ dd if=/dev/zero bs=1 count=1 2>/dev/null | bsdgrep .
Binary file (standard input) matches
Comment 2 y 2014-12-08 01:43:22 UTC
It seems locale-dependent.

stall:
dd if=/dev/zero bs=1 count=1 | env LC_CTYPE=ja_JP.eucJP fgrep -i 1

not stall:
dd if=/dev/zero bs=1 count=1 | env LC_CTYPE=ja_JP.UTF-8 fgrep -i 1
Comment 3 Kyle Evans freebsd_committer freebsd_triage 2017-04-20 17:33:18 UTC
As mentioned, this is a locale-dependent bug, and one that exists solely in gnugrep -- not libgnuregex.

Also, as of -HEAD, the inconsistent behavior dt71@gmx.com observes is no longer.

This may be closed when bsdgrep is installed as /usr/bin/grep.
Comment 4 Eitan Adler freebsd_committer freebsd_triage 2018-05-20 23:53:46 UTC
For bugs matching the following conditions:
- Status == In Progress
- Assignee == "bugs@FreeBSD.org"
- Last Modified Year <= 2017

Do
- Set Status to "Open"
Comment 5 commit-hook freebsd_committer freebsd_triage 2020-12-08 14:05:52 UTC
A commit references this bug:

Author: kevans
Date: Tue Dec  8 14:05:26 UTC 2020
New revision: 368439
URL: https://svnweb.freebsd.org/changeset/base/368439

Log:
  src.opts.mk: switch to bsdgrep as /usr/bin/grep

  This has been years in the making, and we all knew it was bound to happen
  some day. Switch to the BSDL grep implementation now that it's been a
  little more thoroughly tested and theoretically supports all of the
  extensions that gnugrep in base had with our libregex(3).

  Folks shouldn't really notice much from this update; bsdgrep is slower than
  gnugrep, but this is currently the price to pay for fewer bugs. Those
  dissatisfied with the speed of grep and in need of a faster implementation
  should check out what textproc/ripgrep and textproc/the_silver_searcher
  can do for them.

  I have some WIP to make bsdgrep faster, but do not consider it a blocker
  when compared to the pros of switching now (aforementioned bugs, licensing).

  PR:		228798 (exp-run)
  PR:		128645, 156704, 166842, 166862, 180937, 193835, 201650
  PR:		232565, 242308, 246000, 251081, 191086, 194397
  Relnotes:	yes, please

Changes:
  head/share/mk/src.opts.mk