From b9591d968a723aab1b121c6008d97cba6b010013 Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Mon, 22 Apr 2024 14:55:50 +0530 Subject: [PATCH] LU-17000 misc: fix strscpy() Coverity warnings Fix warning reported for use of uninitialized vairable CoverityID: 425254 ("Uninitialized scalar variable") Fix warning reported when changing call from strlcpy() to strscpy() CoverityID: 425253 ("Unsigned compared against 0") CoverityID: 425262 ("Unsigned compared against 0") Fixes: 7a0517fa2 ("LU-17592 build: kernel 6.8 removed strlcpy()") Test-Parameters: trivial Signed-off-by: Arshad Hussain Change-Id: Id3804c77a105e4776a0242db787dc1ca2528d9ca Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54865 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Shaun Tancheff Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/kunit/llog_test.c | 2 +- lustre/lod/lod_lov.c | 3 ++- lustre/lov/lov_ea.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lustre/kunit/llog_test.c b/lustre/kunit/llog_test.c index 9936924..5603cfa 100644 --- a/lustre/kunit/llog_test.c +++ b/lustre/kunit/llog_test.c @@ -754,7 +754,7 @@ static int llog_cancel_rec_cb(const struct lu_env *env, static int llog_test_5(const struct lu_env *env, struct obd_device *obd) { struct llog_handle *llh = NULL; - char name[10]; + char name[10] = ""; int rc, rc2; struct llog_mini_rec lmr; struct llog_ctxt *ctxt; diff --git a/lustre/lod/lod_lov.c b/lustre/lod/lod_lov.c index fd0163b..b68f5b2 100644 --- a/lustre/lod/lod_lov.c +++ b/lustre/lod/lod_lov.c @@ -781,9 +781,10 @@ static int lod_gen_component_ea(const struct lu_env *env, objs = &lmm->lmm_objects[0]; } else { struct lov_mds_md_v3 *v3 = (struct lov_mds_md_v3 *)lmm; - size_t cplen = strscpy(v3->lmm_pool_name, + ssize_t cplen = strscpy(v3->lmm_pool_name, lod_comp->llc_pool ? : "\0", sizeof(v3->lmm_pool_name)); + if (cplen < 0) RETURN(cplen); objs = &v3->lmm_objects[0]; diff --git a/lustre/lov/lov_ea.c b/lustre/lov/lov_ea.c index d572e47..44dad1d 100644 --- a/lustre/lov/lov_ea.c +++ b/lustre/lov/lov_ea.c @@ -239,7 +239,7 @@ lsme_unpack(struct lov_obd *lov, struct lov_mds_md *lmm, size_t buf_size, lsme->lsme_layout_gen = le16_to_cpu(lmm->lmm_layout_gen); if (pool_name) { - size_t pool_name_len; + ssize_t pool_name_len; pool_name_len = strscpy(lsme->lsme_pool_name, pool_name, sizeof(lsme->lsme_pool_name)); -- 1.8.3.1