Whamcloud - gitweb
LU-12479 utils: cleanup gcc8 string warnings 86/35586/2
authorShaun Tancheff <stancheff@cray.com>
Mon, 22 Jul 2019 21:11:57 +0000 (14:11 -0700)
committerOleg Drokin <green@whamcloud.com>
Tue, 30 Jul 2019 04:03:07 +0000 (04:03 +0000)
Cleanup some trivial buffer overflows

This patch is back-ported from the following one:
Lustre-commit: 164434eed2161337000257968e37d2714e9c9599
Lustre-change: https://review.whamcloud.com/35354

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/35586
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/utils/lfs.c
lustre/utils/liblustreapi.c

index 447d43c..8ada8f8 100644 (file)
@@ -3211,9 +3211,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_FNV_1A_64;
-               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 a15ad82..376ea1a 100644 (file)
@@ -1190,7 +1190,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';
@@ -1200,8 +1200,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);