]> git.proxmox.com Git - mirror_zfs.git/commitdiff
zdb: Fix handling of nul termination in symlink targets
authorMark Johnston <markjdb@gmail.com>
Fri, 20 May 2022 17:32:49 +0000 (13:32 -0400)
committerGitHub <noreply@github.com>
Fri, 20 May 2022 17:32:49 +0000 (10:32 -0700)
The SA attribute containing the symlink target does not include a nul
terminator, so when printing the target zdb would sometimes include
garbage at the end of the string.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Mark Johnston <markj@FreeBSD.org>
Closes #13482

cmd/zdb/zdb.c

index 3d4d956e569895aa4b213b658f2ccad1c37394b3..ce95759dc708a8ce6210fe71a5d9123ce67b7513 100644 (file)
@@ -3194,13 +3194,18 @@ dump_znode_symlink(sa_handle_t *hdl)
 {
        int sa_symlink_size = 0;
        char linktarget[MAXPATHLEN];
-       linktarget[0] = '\0';
        int error;
 
        error = sa_size(hdl, sa_attr_table[ZPL_SYMLINK], &sa_symlink_size);
        if (error || sa_symlink_size == 0) {
                return;
        }
+       if (sa_symlink_size >= sizeof (linktarget)) {
+               (void) printf("symlink size %d is too large\n",
+                   sa_symlink_size);
+               return;
+       }
+       linktarget[sa_symlink_size] = '\0';
        if (sa_lookup(hdl, sa_attr_table[ZPL_SYMLINK],
            &linktarget, sa_symlink_size) == 0)
                (void) printf("\ttarget %s\n", linktarget);