From e8f24b264d972c6fcedd9497d9c22a9ffd2e4771 Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Thu, 26 Aug 2021 11:57:24 -0500 Subject: [PATCH] EX-3658 pumount: correct path escaping 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 Change-Id: I248f56752b30836636734f43d16741511717709c Reviewed-on: https://review.whamcloud.com/44759 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-on: https://review.whamcloud.com/44959 Tested-by: Andreas Dilger --- lustre/tests/sanity-pumount.sh | 58 ++++++++++++++++++++++++++++++++++++++++-- pumount/pumount.c | 2 +- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/lustre/tests/sanity-pumount.sh b/lustre/tests/sanity-pumount.sh index 3768c46..1519758 100755 --- a/lustre/tests/sanity-pumount.sh +++ b/lustre/tests/sanity-pumount.sh @@ -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 diff --git a/pumount/pumount.c b/pumount/pumount.c index 72fbf58..0d39430 100644 --- a/pumount/pumount.c +++ b/pumount/pumount.c @@ -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++) = '\\'; -- 1.8.3.1