https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=293252
Bug ID: 293252
Summary: grep(1) hangs when trying to colorize multiple
patterns
Product: Base System
Version: 14.3-STABLE
Hardware: Any
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: bin
Assignee: [email protected]
Reporter: [email protected]
To reproduce:
$ printf 'one\ntwo\nthree\n' | /usr/bin/grep --color=always -ie ^ -e wo
one
Expected behavior:
It *should* print all lines (everything matches the "^", but as a zero-width
atom, not highlight it), highlighting the "wo" in "two". This is how Ubuntu's
grep(1) behaves. OpenBSD's grep doesn't support --color so I can't reproduce
there.
Current behavior:
It prints the "one" line then it hangs indefinitely pegging a CPU to 100%
according to top(1).
Observations:
- It works if the second pattern starts at the beginning of a line (searching
for "tw" instead of "wo"):
$ printf 'one\ntwo\nthree\n' | grep --color=always -i -e '^' -e tw
- It works if I don't _also_ search for the beginning of the line:
$ printf 'one\ntwo\nthree\n' | grep --color=always -i -e wo
- It works if I search for '$' as the first pattern instead:
$ printf 'one\ntwo\nthree\n' | grep --color=always -i -e '$' -e wo
- It works if I swap the order of the two:
$ printf 'one\ntwo\nthree\n' | grep --color=always -i -e wo -e ^
If I remove the `--color=always` it works.
$ printf 'one\ntwo\nthree\n' | grep -i -e '^' -e wo
So there's something in the interaction of the three (the `^` pattern coming
first, a second not-starting-at-the-beginning-of-the-line pattern, and the
`--color=always`) that seems to trigger the process-hang/infinite-loop issue.
--
You are receiving this mail because:
You are the assignee for the bug.