From 53ae11aa46eb4c8cff5002b199cd0ea38e129d8e Mon Sep 17 00:00:00 2001 From: Mikhail Pershin Date: Fri, 4 Apr 2025 16:29:07 +0300 Subject: [PATCH] LU-18896 utils: don't miss null-terminator in append_param The code to move tail can skip null-terminator if there is no tail and parameter is the last one. Fixes: f9d346f0c1 ("LU-18587 utils: allow large NID lists in mount tools") Signed-off-by: Mikhail Pershin Change-Id: I088f7a0eda80a9df1d55b19db28793aa488cc95e Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58685 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Alex Zhuravlev Reviewed-by: Oleg Drokin --- lustre/tests/conf-sanity.sh | 19 +++++++++++++++++++ lustre/utils/mount_utils.c | 8 +++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lustre/tests/conf-sanity.sh b/lustre/tests/conf-sanity.sh index 4dd2c81..aeab954 100755 --- a/lustre/tests/conf-sanity.sh +++ b/lustre/tests/conf-sanity.sh @@ -6792,6 +6792,25 @@ test_73b() { } run_test 73b "Large failnode NID list in mountdata" +test_73d() { #LU-18896 + (( $OST1_VERSION >= $(version_code 2.16.53) )) || + skip "need OST >= 2.16.53 for LU-18896 fix" + [[ "$ost1_FSTYPE" == zfs ]] && import_zpool ost1 + + local ostdev=$(ostdevname 1) + + # add bogus param to mountdata + do_facet ost1 "$TUNEFS --erase-params \ + --param=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=1 $ostdev" + do_facet ost1 "$TUNEFS --erase-params --mgsnode=10.23.7.1@tcp \ + --mgsnode=10.23.7.2@tcp $ostdev" + bad=$(do_facet ost1 "$TUNEFS --erase-params" $ostdev | grep -c "xx=1") + reformat + + (( bad == 0 )) || error "garbage in params" +} +run_test 73d "erase + new parameter doesn't corrupt mountdata" + # LU-15246 test_74() { (( $MDS1_VERSION >= $(version_code 2.15.57.16) )) || diff --git a/lustre/utils/mount_utils.c b/lustre/utils/mount_utils.c index 3239d1d..8224929 100644 --- a/lustre/utils/mount_utils.c +++ b/lustre/utils/mount_utils.c @@ -143,7 +143,7 @@ int add_param(char *buf, char *key, char *val) int append_param(char *buf, char *key, char *val, char sep) { - char *ptr = NULL, *next, *cur; + char *ptr = NULL, *next; int bufsize = MAXNIDSTR; int buflen = strlen(buf), vallen = strlen(val); @@ -162,10 +162,8 @@ int append_param(char *buf, char *key, char *val, char sep) } next = strchrnul(ptr, ' '); - cur = buf + buflen; - /* shift tail further at vallen + sep */ - while (cur-- > next) - *(cur + vallen + 1) = *cur; + /* shift all after 'next' further at vallen + sep */ + memmove(next + vallen + 1, next, strlen(next) + 1); /* fill gap with sep + new values */ *next = sep; -- 1.8.3.1