Whamcloud - gitweb
LU-16768 lfs: copy optarg string other than using it directly
authorBobi Jam <bobijam@whamcloud.com>
Wed, 19 Apr 2023 14:19:53 +0000 (22:19 +0800)
committerAndreas Dilger <adilger@whamcloud.com>
Thu, 11 May 2023 00:41:41 +0000 (00:41 +0000)
Copy optarg string for fp_format_printf_str lest it be messed
later.

Lustre-change: https://review.whamcloud.com/50733
Lustre-commit: 75db98cef3df8f9a0e1b6e7a5150f3c332e6167b

Signed-off-by: Bobi Jam <bobijam@whamcloud.com>
Change-Id: Ib32883d3261ae921adf0fdd7b05bcbf728de7557
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/50690
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/utils/lfs.c

index 3fedb27..59b8095 100644 (file)
@@ -5658,7 +5658,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);
@@ -5825,6 +5825,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;
 }