]> arthur.barton.de Git - bup.git/commitdiff
test-meta.sh: escape user/group expressions
authorRob Browning <rlb@defaultvalue.org>
Tue, 14 Oct 2014 17:20:14 +0000 (12:20 -0500)
committerRob Browning <rlb@defaultvalue.org>
Fri, 17 Oct 2014 16:13:13 +0000 (11:13 -0500)
Escape external user/group strings before passing them to 'grep -E',
otherwise calls like this will fail when the string includes regular
expression metacharacters:

Thanks to Pierre-Emmanuel Novac <piernov@gmail.com> for reporting the
problem.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
t/lib.sh
t/test-meta.sh

index 372f0d20d5d5983ee0c8428d3a6cdda9473344c3..84b942137f882aaf138c47e05d867c5a8c7f113e 100644 (file)
--- a/t/lib.sh
+++ b/t/lib.sh
@@ -46,3 +46,8 @@ path-filesystems()
     done
     exit 0
 )
+
+escape-erx()
+{
+    sed 's/[][\.|$(){?+*^]/\\&/g' <<< "$*"
+}
index 2a45620e61da0a1b3e20719408ce5d8f46b37042..0d7034bd49ce8cf90fa2aea101aadacd74a5df4f 100755 (executable)
@@ -433,6 +433,7 @@ src/foo/3"
       print grp.getgrgid(os.getgroups()[0])[0]')" || exit $?
     last_group="$(python -c 'import os,grp; \
       print grp.getgrgid(os.getgroups()[-1])[0]')" || exit $?
+    last_group_erx="$(escape-erx "$last_group")"
 
     WVSTART 'metadata (restoration of ownership)'
     WVPASS force-delete "$TOP/bupmeta.tmp"
@@ -459,7 +460,7 @@ src/foo/3"
     WVPASS rm -rf src
     WVPASS bup meta --edit --set-group "$last_group" ../src.meta \
         | WVPASS bup meta -x
-    WVPASS bup xstat src | WVPASS grep -qE "^group: $last_group"
+    WVPASS bup xstat src | WVPASS grep -qE "^group: $last_group_erx"
 
     # Make sure we can restore one of the user's gids.
     user_gids="$(id -G)"
@@ -537,23 +538,25 @@ src/foo/3"
 
     other_uinfo2="$(id-other-than --user "$(id -un)" "$other_user")"
     other_user2="${other_uinfo2%%:*}"
+    other_user2_erx="$(escape-erx "$other_user2")"
     other_uid2="${other_uinfo2##*:}"
 
     other_ginfo2="$(id-other-than --group "$(id -gn)" "$other_group")"
     other_group2="${other_ginfo2%%:*}"
+    other_group2_erx="$(escape-erx "$other_group2")"
     other_gid2="${other_ginfo2##*:}"
 
     # Try to restore a user (and see that user trumps uid when uid is not 0).
     WVPASS bup meta --edit \
         --set-uid "$other_uid" --set-user "$other_user2" ../src.meta \
         | WVPASS bup meta -x
-    WVPASS bup xstat src | WVPASS grep -qE "^user: $other_user2"
+    WVPASS bup xstat src | WVPASS grep -qE "^user: $other_user2_erx"
 
     # Try to restore a group (and see that group trumps gid when gid is not 0).
     WVPASS bup meta --edit \
         --set-gid "$other_gid" --set-group "$other_group2" ../src.meta \
         | WVPASS bup meta -x
-    WVPASS bup xstat src | WVPASS grep -qE "^group: $other_group2"
+    WVPASS bup xstat src | WVPASS grep -qE "^group: $other_group2_erx"
 
     # Test --numeric-ids (uid).  Note the name 'root' is not handled
     # specially, so we use that here as the test user name.  We assume
@@ -598,13 +601,13 @@ src/foo/3"
         # Make sure a uid of 0 trumps a non-root user.
         WVPASS bup meta --edit --set-user "$other_user2" ../src.meta \
             | WVPASS bup meta -x
-        WVPASS bup xstat src | WVPASS grep -qvE "^user: $other_user2"
+        WVPASS bup xstat src | WVPASS grep -qvE "^user: $other_user2_erx"
         WVPASS bup xstat src | WVPASS grep -qE "^uid: 0"
 
         # Make sure a gid of 0 trumps a non-root group.
         WVPASS bup meta --edit --set-group "$other_group2" ../src.meta \
             | WVPASS bup meta -x
-        WVPASS bup xstat src | WVPASS grep -qvE "^group: $other_group2"
+        WVPASS bup xstat src | WVPASS grep -qvE "^group: $other_group2_erx"
         WVPASS bup xstat src | WVPASS grep -qE "^gid: 0"
     fi
 ) || exit $?