Whamcloud - gitweb
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 c990a93..61b6319 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 efc348b..b894856 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 307aecc..bff65c1 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,