Whamcloud - gitweb
EX-3658 pumount: correct path escaping
authorJohn L. Hammond <jhammond@whamcloud.com>
Thu, 26 Aug 2021 16:57:24 +0000 (11:57 -0500)
committerAndreas Dilger <adilger@whamcloud.com>
Fri, 17 Sep 2021 23:53:03 +0000 (23:53 +0000)
Correct the test for whether a character needs escaping in
pu_str_escape2(). Add sanity-pumount 55f-g to verify.

Test-Parameters: trivial testlist=sanity-pumount clientextra_install_params="--packages pumount"
Signed-off-by: John L. Hammond <jhammond@whamcloud.com>
Change-Id: I248f56752b30836636734f43d16741511717709c
Reviewed-on: https://review.whamcloud.com/44759
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/44959
Tested-by: Andreas Dilger <adilger@whamcloud.com>
lustre/tests/sanity-pumount.sh
pumount/pumount.c

index 3768c46..1519758 100755 (executable)
@@ -7,7 +7,7 @@ ALWAYS_EXCEPT="$SANITY_PUMOUNT_EXCEPT"
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
 SRCDIR=$(dirname $0)
-PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
+PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$SRCDIR/../../pumount:$PATH
 
 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
 OPENFILE=${OPENFILE:-openfile}
@@ -174,7 +174,7 @@ test_20c() {
                umount_client "$MOUNT2"
 
                if pumount $option "$MOUNT2"; then
-                       error "pumount $opt should fail"
+                       error "'pumount $option' should fail"
                fi
        done
 }
@@ -630,6 +630,60 @@ test_55e() {
 }
 run_test 55e "pumount --print shows the right path (sort of)"
 
+test_55f() {
+       local dir=$(readlink --canonicalize "$DIR")
+       local name_esc='.\014\023\024\022:VOLATILE:0000:55f055f0'
+       local file=$(printf "%s/${name_esc}" "$dir")
+       local path
+       local fd
+       local pid
+
+       init_pumount_env
+
+       exec {fd}>"$file"
+       sleep $SLEEP_TIME &
+       pid=$!
+       exec {fd}>&-
+       sleep 1
+
+       # COMM=1 PID=2 REF=3 HANDLE_TYPE=4 HANDLE=5 PATH=6
+       path=$(pumount --dry-run "$MOUNT1" |
+               awk -v pid=$pid -v fd=$fd '$2 == pid && $3 == fd { print $6; }')
+
+       [[ "${path}" == "${dir}/${name_esc}" ]] ||
+               error "got escaped path '${path}, expected '${dir}/${name_esc}'"
+
+       kill_wait_signaled $pid $SIGKILL $SIGKILL
+}
+run_test 55f "pumount escapes volatile file paths correctly"
+
+test_55g() {
+       local dir=$(readlink --canonicalize "$DIR")
+       local file="$DIR/$tfile $tfile"
+       local path_esc="${dir}/${tfile}\040${tfile}"
+       local path
+       local fd
+       local pid
+
+       init_pumount_env
+
+       exec {fd}>"$file"
+       sleep $SLEEP_TIME &
+       pid=$!
+       exec {fd}>&-
+       sleep 1
+
+       # COMM=1 PID=2 REF=3 HANDLE_TYPE=4 HANDLE=5 PATH=6
+       path=$(pumount --dry-run "$MOUNT1" |
+               awk -v pid=$pid -v fd=$fd '$2 == pid && $3 == fd { print $6; }')
+
+       [[ "${path}" == "${path_esc}" ]] ||
+               error "got escaped path '${path}', expected '${path_esc}'"
+
+       kill_wait_signaled $pid $SIGKILL $SIGKILL
+}
+run_test 55g "pumount escapes paths with spaces correctly"
+
 test_56a() {
        local file=$DIR/$tfile
        local fd
index 72fbf58..0d39430 100644 (file)
@@ -169,7 +169,7 @@ static char *pu_str_escape2(const char *str, size_t count)
        while (s < str + count) {
                int c = *(s++);
 
-               if (!isprint(c) || strchr(" \t\n\v\f\r\\", c) == NULL) {
+               if (isprint(c) && strchr(" \a\b\t\n\v\f\r\\", c) == NULL) {
                        *(e++) = c;
                } else {
                        *(e++) = '\\';