Page MenuHomeFreeBSD

zgrep: multiple fixes
Needs RevisionPublic

Authored by bapt on May 4 2018, 6:32 PM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 19 2024, 10:39 PM
Unknown Object (File)
Jan 18 2024, 8:06 AM
Unknown Object (File)
Dec 20 2023, 8:20 AM
Unknown Object (File)
Dec 15 2023, 7:02 PM
Unknown Object (File)
Sep 16 2023, 3:59 AM
Unknown Object (File)
Aug 14 2023, 7:29 AM
Unknown Object (File)
Jun 28 2023, 3:41 PM
Unknown Object (File)
Jun 10 2023, 3:03 AM
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