Whamcloud - gitweb
LU-12479 utils: cleanup gcc8 string warnings 54/35354/3
authorShaun Tancheff <stancheff@cray.com>
Fri, 28 Jun 2019 01:06:39 +0000 (20:06 -0500)
committerOleg Drokin <green@whamcloud.com>
Sat, 27 Jul 2019 00:21:46 +0000 (00:21 +0000)
Cleanup some trivial buffer overflows

Test-Parameters: trivial
Cray-bug-id: LUS-6962
Signed-off-by: Shaun Tancheff <stancheff@cray.com>
Change-Id: I17dd1d042c4050e351aca856931ce1107fd5b08f
Reviewed-on: https://review.whamcloud.com/35354
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
lustre/utils/lfs.c
lustre/utils/liblustreapi.c

index 7db51ce..f1af46a 100644 (file)
@@ -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;
 
index 429b27d..4e04559 100644 (file)
@@ -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);