Whamcloud - gitweb
LU-16721 lfs: Fix path2fid segfault 57/50557/5
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Thu, 6 Apr 2023 07:00:45 +0000 (03:00 -0400)
committerOleg Drokin <green@whamcloud.com>
Sat, 22 Apr 2023 17:31:45 +0000 (17:31 +0000)
This patch fixes segfault when calling path2fid
under interactive mode.

Before Patch
============
lfs > path2fid /mnt/lustre/a
[0x200000401:0x1:0x0]
Segmentation fault

After Patch
============
$ lfs
lfs > path2fid /mnt/lustre/a
[0x200000401:0x1:0x0]

lfs > path2fid --parent /mnt/lustre/a
[0x200000007:0x1:0x0]/a
lfs >

Testcase sanity/154h added.

Test-Parameters: trivial testlist=sanity
Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: I4693e0d476e9e7f570f45fd7a31d275d549245aa
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50557
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/sanity.sh
lustre/utils/lfs.c

index 0858a23..d8d99db 100755 (executable)
@@ -16250,6 +16250,26 @@ test_154g()
 }
 run_test 154g "various llapi FID tests"
 
+test_154h()
+{
+       (( $CLIENT_VERSION >= $(version_code 2.15.55.1) )) ||
+               skip "Need client at least version 2.15.55.1"
+
+       # Create an empty file
+       touch $DIR/$tfile
+
+       # Get FID (interactive mode) and save under $TMP/$tfile.log
+       $LFS 2>&1 <<-EOF | tee $TMP/$tfile.log
+               path2fid $DIR/$tfile
+       EOF
+
+       fid=$(cat $TMP/$tfile.log)
+       # $fid should not be empty
+       [[ ! -z $fid ]] || error "FID is empty"
+       $LFS rmfid $DIR "$fid" || error "rmfid failed for $fid"
+}
+run_test 154h "Verify interactive path2fid"
+
 test_155_small_load() {
     local temp=$TMP/$tfile
     local file=$DIR/$tfile
index 7c36bdc..4521b77 100644 (file)
@@ -9818,7 +9818,7 @@ static int lfs_path2fid(int argc, char **argv)
        }
 
        rc = 0;
-       for (path = argv + optind; *path != NULL; path++) {
+       for (path = argv + optind; optind < argc; path++, optind++) {
                int err = 0;
 
                if (!show_parents) {