Whamcloud - gitweb
LU-12999 mgs: Cleanup string handling in name_create_mdt 17/36817/5
authorShaun Tancheff <stancheff@cray.com>
Mon, 2 Dec 2019 17:32:50 +0000 (11:32 -0600)
committerOleg Drokin <green@whamcloud.com>
Mon, 16 Dec 2019 06:00:01 +0000 (06:00 +0000)
To satisfy gcc8 -Werror=format-overflow sanity test the mdt_idx
before calling snprintf.

Cray-bug-id: LUS-8186
Signed-off-by: Shaun Tancheff <stancheff@cray.com>
Change-Id: I2c8764d3715290ee2bd8c96cdc98b532f50632c6
Reviewed-on: https://review.whamcloud.com/36817
Reviewed-by: Petros Koutoupis <pkoutoupis@cray.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Ben Evans <bevans@cray.com>
Reviewed-by: Arshad Hussain <arshad.super@gmail.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/mgs/mgs_internal.h
lustre/mgs/mgs_llog.c

index b7314a5..539b8d1 100644 (file)
@@ -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 */
index 841afcd..b9d8550 100644 (file)
@@ -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);
 }
 
 /**