From 75db98cef3df8f9a0e1b6e7a5150f3c332e6167b Mon Sep 17 00:00:00 2001 From: Bobi Jam Date: Tue, 25 Apr 2023 10:15:11 +0800 Subject: [PATCH] LU-16768 lfs: copy optarg string other than using it directly 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 Change-Id: Ib32883d3261ae921adf0fdd7b05bcbf728de7557 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50733 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Rick Mohr Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/utils/lfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 2888070..2152d74 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -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(¶m.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; } -- 1.8.3.1