Browse Source

Avoid grep ambiguities

Where regular expression is read from a variable and -e argument is not
provided, the resulting call may end up being interpreted as grep
argument,  This can be pretty dangerous, eg. if the variable expands to
`--help`, grep help is shown and grep exits with zero, which would be
interprered as match.  Another example is when the variable expands to
a valid grep parameter; this would mean that next argument would be
interprered by grep as the regex, and if the argument after that would
be missing, grep would read stdin, resulting in data messup or grep
waiting
indefinitely.

See also:

    https://github.com/koalaman/shellcheck/issues/1342
Alois Mahdal 5 years ago
parent
commit
64964d7049
2 changed files with 2 additions and 2 deletions
  1. 1
    1
      src/bin/sfdoc
  2. 1
    1
      src/shellfu.sh.skel

+ 1
- 1
src/bin/sfdoc View File

@@ -134,7 +134,7 @@ main() {
134 134
     esac
135 135
     case $action in
136 136
         exp)    # --export
137
-            grep -qw "$format" <<<manpage,markdown,pod \
137
+            grep -qwe "$format" <<<manpage,markdown,pod \
138 138
              || die "unknown format: $format"
139 139
             sfdoc__export "$format" "${RealModuleName:-$module}" "$mpath" "$encoding"
140 140
             ;;

+ 1
- 1
src/shellfu.sh.skel View File

@@ -230,7 +230,7 @@ shellfu() {
230 230
             # True if module $1 is already imported
231 231
             #
232 232
             local mname=$1
233
-            echo "$__SHELLFU_IMPORTED" | tr : \\n | grep -qx "$mname"
233
+            echo "$__SHELLFU_IMPORTED" | tr : \\n | grep -qxe "$mname"
234 234
             ;;
235 235
 
236 236
         _list_mfiles)