From: Shaun Tancheff Date: Fri, 28 Jun 2019 01:06:39 +0000 (-0500) Subject: LU-12479 utils: cleanup gcc8 string warnings X-Git-Tag: 2.12.57~91 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=36fcb2c26ec411cf83f4a9a3c86dbc417c854e7c LU-12479 utils: cleanup gcc8 string warnings Cleanup some trivial buffer overflows Test-Parameters: trivial Cray-bug-id: LUS-6962 Signed-off-by: Shaun Tancheff Change-Id: I17dd1d042c4050e351aca856931ce1107fd5b08f Reviewed-on: https://review.whamcloud.com/35354 Reviewed-by: Andreas Dilger Tested-by: jenkins Tested-by: Maloo Reviewed-by: Alex Zhuravlev --- diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 7db51ce..f1af46a 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -3561,9 +3561,11 @@ static int lfs_setstripe_internal(int argc, char **argv, lmu->lum_hash_type = lsa.lsa_pattern; else lmu->lum_hash_type = LMV_HASH_TYPE_DEFAULT; - if (lsa.lsa_pool_name) + if (lsa.lsa_pool_name) { strncpy(lmu->lum_pool_name, lsa.lsa_pool_name, sizeof(lmu->lum_pool_name) - 1); + lmu->lum_pool_name[sizeof(lmu->lum_pool_name) - 1] = 0; + } if (lsa.lsa_nr_tgts > 1) { int i; diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 429b27d..4e04559 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -1297,7 +1297,7 @@ int get_root_path(int want, char *fsname, int *outfd, char *path, int index) /* If the path isn't set return the first one we find */ if (path == NULL || strlen(path) == 0) { strncpy(mntdir, mnt.mnt_dir, sizeof(mntdir) - 1); - mntdir[strlen(mnt.mnt_dir)] = '\0'; + mntdir[sizeof(mntdir) - 1] = '\0'; if ((want & WANT_FSNAME) && fsname != NULL) { strncpy(fsname, ptr, ptr_end - ptr); fsname[ptr_end - ptr] = '\0'; @@ -1307,8 +1307,8 @@ int get_root_path(int want, char *fsname, int *outfd, char *path, int index) /* Otherwise find the longest matching path */ } else if ((strlen(path) >= mntlen) && (mntlen >= len) && (strncmp(mnt.mnt_dir, path, mntlen) == 0)) { - strncpy(mntdir, mnt.mnt_dir, sizeof(mntdir)); - mntdir[strlen(mnt.mnt_dir)] = '\0'; + strncpy(mntdir, mnt.mnt_dir, sizeof(mntdir) - 1); + mntdir[sizeof(mntdir) - 1] = '\0'; len = mntlen; if ((want & WANT_FSNAME) && fsname != NULL) { strncpy(fsname, ptr, ptr_end - ptr);