From: Shaun Tancheff Date: Mon, 2 Dec 2019 17:32:50 +0000 (-0600) Subject: LU-12999 mgs: Cleanup string handling in name_create_mdt X-Git-Tag: 2.13.51~75 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=298cdb5c0b6136b91e76c9c515bfbc2df99bae0b 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 --- 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); } /**