Whamcloud - gitweb
LU-12479 utils: cleanup gcc8 string warnings 54/35354/2
authorShaun Tancheff <stancheff@cray.com>
Fri, 28 Jun 2019 01:06:39 +0000 (20:06 -0500)
committerShaun Tancheff <stancheff@cray.com>
Sun, 21 Jul 2019 15:00:21 +0000 (10:00 -0500)
Cleanup some trivial buffer overflows

Test-Parameters: trivial
Cray-bug-id: LUS-6962
Signed-off-by: Shaun Tancheff <stancheff@cray.com>
Change-Id: I17dd1d042c4050e351aca856931ce1107fd5b08f

lustre/utils/lfs.c
lustre/utils/liblustreapi.c

index 6927d84..3efdd50 100644 (file)
@@ -3528,9 +3528,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);