Whamcloud - gitweb
LU-16768 lfs: copy optarg string other than using it directly 33/50733/2
authorBobi Jam <bobijam@whamcloud.com>
Tue, 25 Apr 2023 02:15:11 +0000 (10:15 +0800)
committerOleg Drokin <green@whamcloud.com>
Tue, 9 May 2023 05:46:00 +0000 (05:46 +0000)
Copy optarg string for fp_format_printf_str lest it be messed
later.

Fixes: 6b8e97b76c ("LU-10378 utils: add formatted printf to lfs find")
Signed-off-by: Bobi Jam <bobijam@whamcloud.com>
Change-Id: Ib32883d3261ae921adf0fdd7b05bcbf728de7557
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50733
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Rick Mohr <mohrrf@ornl.gov>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/utils/lfs.c

index 2888070..2152d74 100644 (file)
@@ -5777,7 +5777,7 @@ err_free:
                case 'P': /* we always print, this option is a no-op */
                        break;
                case LFS_PRINTF_OPT:
-                       param.fp_format_printf_str = optarg;
+                       param.fp_format_printf_str = strdup(optarg);
                        break;
                case LFS_PROJID_OPT:
                        rc = name2projid(&param.fp_projid, optarg);
@@ -5965,6 +5965,9 @@ err:
        if (param.fp_mdt_uuid && param.fp_num_alloc_mdts)
                free(param.fp_mdt_uuid);
 
+       if (param.fp_format_printf_str)
+               free(param.fp_format_printf_str);
+
        return ret;
 }