Quellcode durchsuchen

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 vor 5 Jahren
Ursprung
Commit
64964d7049
2 geänderte Dateien mit 2 neuen und 2 gelöschten Zeilen
  1. 1
    1
      src/bin/sfdoc
  2. 1
    1
      src/shellfu.sh.skel

+ 1
- 1
src/bin/sfdoc Datei anzeigen

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

+ 1
- 1
src/shellfu.sh.skel Datei anzeigen

230
             # True if module $1 is already imported
230
             # True if module $1 is already imported
231
             #
231
             #
232
             local mname=$1
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
         _list_mfiles)
236
         _list_mfiles)