]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Fix coverity defects: 147480, 147584
authorTobin Harding <me@tobin.cc>
Mon, 16 Oct 2017 22:32:48 +0000 (09:32 +1100)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 16 Oct 2017 22:32:48 +0000 (15:32 -0700)
CID 147480: Logically dead code (DEADCODE)

Remove non-null check and subsequent function call. Add ASSERT to future
proof the code.

usage label is only jumped to before `zhp` is initialized.

CID 147584: Out-of-bounds access (OVERRUN)

Subtract length of current string from buffer length for `size` argument
to `snprintf`.

Starting address for the write is the start of the buffer + the current
string length. We need to subtract this string length else risk a buffer
overflow.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tobin C. Harding <me@tobin.cc>
Closes #6745

cmd/zdb/zdb.c
cmd/zfs/zfs_main.c

index ae8d00f154427bd5a8b2b51bea8d638a1a14fed6..af34bd9ad533636cbe39f20d59576de4be409db3 100644 (file)
@@ -2001,13 +2001,13 @@ dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header,
        aux[0] = '\0';
 
        if (doi.doi_checksum != ZIO_CHECKSUM_INHERIT || verbosity >= 6) {
-               (void) snprintf(aux + strlen(aux), sizeof (aux), " (K=%s)",
-                   ZDB_CHECKSUM_NAME(doi.doi_checksum));
+               (void) snprintf(aux + strlen(aux), sizeof (aux) - strlen(aux),
+                   " (K=%s)", ZDB_CHECKSUM_NAME(doi.doi_checksum));
        }
 
        if (doi.doi_compress != ZIO_COMPRESS_INHERIT || verbosity >= 6) {
-               (void) snprintf(aux + strlen(aux), sizeof (aux), " (Z=%s)",
-                   ZDB_COMPRESS_NAME(doi.doi_compress));
+               (void) snprintf(aux + strlen(aux), sizeof (aux) - strlen(aux),
+                   " (Z=%s)", ZDB_COMPRESS_NAME(doi.doi_compress));
        }
 
        (void) printf("%10lld  %3u  %5s  %5s  %5s  %6s  %5s  %6s  %s%s\n",
index b9b53f22b5c9e31a3d3f5ea027dcbc2b36311505..26096e11529a3ed7cce0f45f653aa825e3bb8ce6 100644 (file)
@@ -785,8 +785,7 @@ zfs_do_clone(int argc, char **argv)
        return (!!ret);
 
 usage:
-       if (zhp)
-               zfs_close(zhp);
+       ASSERT3P(zhp, ==, NULL);
        nvlist_free(props);
        usage(B_FALSE);
        return (-1);