]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
debugfs: fix "ls -p" to avoid printing garbage after the file name
authorTheodore Ts'o <tytso@mit.edu>
Mon, 24 Jul 2017 17:11:16 +0000 (13:11 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 24 Jul 2017 17:11:16 +0000 (13:11 -0400)
In commit 68a1de3df3 (debugfs: pretty print encrypted filenames in the
ls command), a change was introduced in debugfs/ls.c which instead of
copying dirent->name and 0-terminating it, dirent->name is used
directly in printf.

However, instead of using the precision to limit the number of
characters output, the code uses the field width. As a result,
characters are output until a 0 is read, which results in garbage
after the file name.

Also fix two other instances of this in debugging messages that aren't
used, but fixing them will avoid potential future copypasta bugs.

Reported-by: Christian Gabriel <ch_gabriel@web.de>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
debugfs/ls.c
lib/blkid/read.c
lib/ext2fs/namei.c

index c990a93da7bfe89912d1b47003c5d7bf70319b58..61b6319675d07d9655ea1d7cf924b7fe57388f48 100644 (file)
@@ -122,7 +122,7 @@ static int list_dir_proc(ext2_ino_t dir EXT2FS_ATTR((unused)),
                                return 0;
                } else
                        memset(&inode, 0, sizeof(struct ext2_inode));
-               fprintf(ls->f,"/%u/%06o/%d/%d/%*s/", ino, inode.i_mode,
+               fprintf(ls->f,"/%u/%06o/%d/%d/%.*s/", ino, inode.i_mode,
                        inode.i_uid, inode.i_gid, thislen, dirent->name);
                if (LINUX_S_ISDIR(inode.i_mode))
                        fprintf(ls->f, "/");
index efc348b941b23ae5d0400bada869f87a35eba7c1..b8948564c0d3a8660873d41cac9725b7c243c676 100644 (file)
@@ -199,7 +199,7 @@ static int parse_dev(blkid_cache cache, blkid_dev *dev, char **cp)
        start = skip_over_blank(start + 1);
        end = skip_over_word(start);
 
-       DBG(DEBUG_READ, printf("device should be %*s\n",
+       DBG(DEBUG_READ, printf("device should be %.*s\n",
                               (int)(end - start), start));
 
        if (**cp == '>')
index 307aecc88d878e08b675fe0bd0cc7ab2953d6dee..bff65c1bb106ddec43f134f5befe4852eb34c56a 100644 (file)
@@ -128,7 +128,7 @@ static errcode_t open_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t base,
        errcode_t retval;
 
 #ifdef NAMEI_DEBUG
-       printf("open_namei: root=%lu, dir=%lu, path=%*s, lc=%d\n",
+       printf("open_namei: root=%lu, dir=%lu, path=%.*s, lc=%d\n",
               root, base, pathlen, pathname, link_count);
 #endif
        retval = dir_namei(fs, root, base, pathname, pathlen,