From 298cdb5c0b6136b91e76c9c515bfbc2df99bae0b Mon Sep 17 00:00:00 2001 From: Shaun Tancheff Date: Mon, 2 Dec 2019 11:32:50 -0600 Subject: [PATCH] LU-12999 mgs: Cleanup string handling in name_create_mdt To satisfy gcc8 -Werror=format-overflow sanity test the mdt_idx before calling snprintf. Cray-bug-id: LUS-8186 Signed-off-by: Shaun Tancheff Change-Id: I2c8764d3715290ee2bd8c96cdc98b532f50632c6 Reviewed-on: https://review.whamcloud.com/36817 Reviewed-by: Petros Koutoupis Tested-by: jenkins Tested-by: Maloo Reviewed-by: Ben Evans Reviewed-by: Arshad Hussain Reviewed-by: Oleg Drokin --- lustre/mgs/mgs_internal.h | 1 + lustre/mgs/mgs_llog.c | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lustre/mgs/mgs_internal.h b/lustre/mgs/mgs_internal.h index b7314a5..539b8d1 100644 --- a/lustre/mgs/mgs_internal.h +++ b/lustre/mgs/mgs_internal.h @@ -106,6 +106,7 @@ struct mgs_tgt_srpc_conf { }; #define INDEX_MAP_SIZE 8192 /* covers indicies to FFFF */ +#define INDEX_MAP_MAX_VALUE ((INDEX_MAP_SIZE * 8) - 1) #define FSDB_LOG_EMPTY (0) /* missing client log */ #define FSDB_OLDLOG14 (1) /* log starts in old (1.4) style */ diff --git a/lustre/mgs/mgs_llog.c b/lustre/mgs/mgs_llog.c index 841afcd..b9d8550 100644 --- a/lustre/mgs/mgs_llog.c +++ b/lustre/mgs/mgs_llog.c @@ -1534,12 +1534,15 @@ static int only_mgs_is_running(struct obd_device *mgs_obd) return (num_devices <= 3) && (num_exports == 0); } -static int name_create_mdt(char **logname, char *fsname, int i) +static int name_create_mdt(char **logname, char *fsname, int mdt_idx) { - char mdt_index[9]; + char postfix[9]; - sprintf(mdt_index, "-MDT%04x", i); - return name_create(logname, fsname, mdt_index); + if (mdt_idx > INDEX_MAP_MAX_VALUE) + return -E2BIG; + + snprintf(postfix, sizeof(postfix), "-MDT%04x", mdt_idx); + return name_create(logname, fsname, postfix); } /** -- 1.8.3.1