瀏覽代碼

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 年之前
父節點
當前提交
64964d7049
共有 2 個文件被更改,包括 2 次插入2 次删除
  1. 1
    1
      src/bin/sfdoc
  2. 1
    1
      src/shellfu.sh.skel

+ 1
- 1
src/bin/sfdoc 查看文件

@@ -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 查看文件

@@ -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)