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.
Alois Mahdal 5 years ago
parent
commit
c928c56273
1 changed files with 3 additions and 3 deletions
  1. 3
    3
      src/shellfu/dottum.sh

+ 3
- 3
src/shellfu/dottum.sh View File

165
     #
165
     #
166
     local item=$1
166
     local item=$1
167
     debug -v item
167
     debug -v item
168
-    Verbose=false dottum__lsvault | grep -qxF "$item"   && return 1
169
-    Verbose=false dottum__lsvault | grep -qx "$item/.*" && return 1
168
+    Verbose=false dottum__lsvault | grep -qxFe "$item"   && return 1
169
+    Verbose=false dottum__lsvault | grep -qxe "$item/.*" && return 1
170
     return 0
170
     return 0
171
 }
171
 }
172
 
172
 
194
     local item
194
     local item
195
     find "$vlt" -mindepth 1 -maxdepth 1 -printf "%P\n" \
195
     find "$vlt" -mindepth 1 -maxdepth 1 -printf "%P\n" \
196
       | dottum__pfxpath "$vlt/" \
196
       | dottum__pfxpath "$vlt/" \
197
-      | grep -v "$DOTTUM__VAULT/dotvault" \
197
+      | grep -ve "$DOTTUM__VAULT/dotvault" \
198
       | while IFS= read -r item;
198
       | while IFS= read -r item;
199
         do
199
         do
200
             dottum__istarget "$item" && echo "$item"
200
             dottum__istarget "$item" && echo "$item"