Page MenuHomeFreeBSD

zgrep: multiple fixes
AbandonedPublic

Authored by bapt on May 4 2018, 6:32 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Oct 15, 6:02 AM
Unknown Object (File)
Mon, Oct 13, 9:06 AM
Unknown Object (File)
Sat, Oct 11, 1:02 AM
Unknown Object (File)
Thu, Oct 9, 11:52 PM
Unknown Object (File)
Wed, Sep 24, 9:20 PM
Unknown Object (File)
Sep 18 2025, 1:20 PM
Unknown Object (File)
Sep 17 2025, 10:17 PM
Unknown Object (File)
Sep 16 2025, 5:04 PM
Subscribers

Details

Reviewers
kevans
jilles
Summary

Fix multiple -e pattern options
-f is now working as expected
Protect arguments with space with an eval trick

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 17054
Build 16917: arc lint + arc unit

Event Timeline

jilles requested changes to this revision.May 6 2018, 9:15 PM
jilles added inline comments.
usr.bin/grep/zgrep.sh
99–100

This needs some sort of quoting to make it come out correctly after eval. Something like this (inspired by ltr in etc/rc.subr) should work:

quote() {
    local part IFS=\'; set -- $1""
    unset quote_result
    for part do
        quote_result=${quote_result+$quote_result\'\\\'\'}$part
    done
}

then surround $quote_result with single-quotes.

151

Suggest passing the parameter expansions literally to eval when possible (all except ${grep_args}) to avoid inappropriate expansion.

This revision now requires changes to proceed.May 6 2018, 9:15 PM

Properly quotes the arguments where needed

bapt marked an inline comment as done.Jun 6 2018, 10:30 PM
bapt added inline comments.
usr.bin/grep/zgrep.sh
151

Do you have examples of possible inappropriate expansions?

jilles requested changes to this revision.Jun 7 2018, 9:48 PM
jilles added inline comments.
usr.bin/grep/zgrep.sh
151

A pattern containing a double-quote. The way this is currently written, the double-quote will be special and the pattern will not be interpreted as expected.

Using the quote function as for grep_args will make this work; alternatively, use something like `eval ...'${need_pattern:+"${pattern}"}'. The single-quotes ensure a single pass through the parser and expansion for the pattern string.

For cattool and catargs you get away with doing it like this because there are no problematic special characters in those.

This revision now requires changes to proceed.Jun 7 2018, 9:48 PM