]> granicus.if.org Git - zfs/commitdiff
Fix coverity defects: CID 147443, 147656, 147655, 147441, 147653
authorBearBabyLiu <liu.huang@zte.com.cn>
Thu, 29 Sep 2016 20:33:09 +0000 (04:33 +0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 29 Sep 2016 20:33:09 +0000 (13:33 -0700)
coverity scan CID:147443, Type: Buffer not null terminated
coverity scan CID:147656, Type: Copy into fixed size buffer
coverity scan CID:147655, Type: Copy into fixed size buffer
coverity scan CID:147441, Type: Buffer not null terminated
coverity scan CID:147653, Type: Copy into fixed size buffer

Reviewed-by: Richard Laager <rlaager@wiktel.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: liuhuang <liu.huang@zte.com.cn>
Closes #5165

cmd/zfs/zfs_main.c
cmd/zinject/zinject.c
lib/libzfs/libzfs_changelist.c
lib/libzfs/libzfs_diff.c
lib/libzfs/libzfs_util.c

index a4ffb1f4471f06c6a72d945c07db430db56be662..bf9a7924801f46e79e47ad27d35e3420cf01af19 100644 (file)
@@ -6768,7 +6768,7 @@ zfs_do_bookmark(int argc, char **argv)
                 * Snapshot name begins with @.
                 * Default to same fs as bookmark.
                 */
-               (void) strncpy(snapname, argv[1], sizeof (snapname));
+               (void) strlcpy(snapname, argv[1], sizeof (snapname));
                *strchr(snapname, '#') = '\0';
                (void) strlcat(snapname, argv[0], sizeof (snapname));
        } else {
index 0ce50277dfebcbf03ef5ed5c06e81f7036d20073..396c52a0c82f281981764d299fc39fc7b9f84948 100644 (file)
@@ -548,7 +548,7 @@ register_handler(const char *pool, int flags, zinject_record_t *record,
 {
        zfs_cmd_t zc = {"\0"};
 
-       (void) strcpy(zc.zc_name, pool);
+       (void) strlcpy(zc.zc_name, pool, sizeof (zc.zc_name));
        zc.zc_inject_record = *record;
        zc.zc_guid = flags;
 
index 5e007c0f48423eafbd023b9a10c7d38f3b0cc3fb..ed11bb8227bcc9dce49ce3c3f15e6cbc6e00e3f5 100644 (file)
@@ -304,7 +304,8 @@ changelist_rename(prop_changelist_t *clp, const char *src, const char *dst)
                remove_mountpoint(cn->cn_handle);
 
                (void) strlcpy(newname, dst, sizeof (newname));
-               (void) strcat(newname, cn->cn_handle->zfs_name + strlen(src));
+               (void) strlcat(newname, cn->cn_handle->zfs_name + strlen(src),
+                   sizeof (newname));
 
                (void) strlcpy(cn->cn_handle->zfs_name, newname,
                    sizeof (cn->cn_handle->zfs_name));
index f5c799529c6eb840f79bc0317a22e060a82e8d42..419189aa8d7ea17989c1d309c17b0d2a1d9426a3 100644 (file)
@@ -425,7 +425,7 @@ differ(void *arg)
 
        if ((ofp = fdopen(di->outputfd, "w")) == NULL) {
                di->zerr = errno;
-               strncpy(di->errbuf, strerror(errno), sizeof (di->errbuf));
+               strlcpy(di->errbuf, strerror(errno), sizeof (di->errbuf));
                (void) close(di->datafd);
                return ((void *)-1);
        }
index 4988e8115dca4c5f30a75a53b5e1afae421e6826..8fec78283879afb5514c578ba158e29b0104ba31 100755 (executable)
@@ -1107,8 +1107,8 @@ zfs_strcmp_pathname(char *name, char *cmp, int wholedisk)
        dup = strdup(cmp);
        dir = strtok(dup, "/");
        while (dir) {
-               strcat(cmp_name, "/");
-               strcat(cmp_name, dir);
+               strlcat(cmp_name, "/", sizeof (cmp_name));
+               strlcat(cmp_name, dir, sizeof (cmp_name));
                dir = strtok(NULL, "/");
        }
        free(dup);