From b55571cdf7206b780ff4116ca975fd8d3af5f353 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 24 Jul 2017 13:11:16 -0400 Subject: [PATCH] debugfs: fix "ls -p" to avoid printing garbage after the file name 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 Signed-off-by: Theodore Ts'o --- debugfs/ls.c | 2 +- lib/blkid/read.c | 2 +- lib/ext2fs/namei.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/debugfs/ls.c b/debugfs/ls.c index c990a93..61b6319 100644 --- a/debugfs/ls.c +++ b/debugfs/ls.c @@ -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, "/"); diff --git a/lib/blkid/read.c b/lib/blkid/read.c index efc348b..b894856 100644 --- a/lib/blkid/read.c +++ b/lib/blkid/read.c @@ -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 == '>') diff --git a/lib/ext2fs/namei.c b/lib/ext2fs/namei.c index 307aecc..bff65c1 100644 --- a/lib/ext2fs/namei.c +++ b/lib/ext2fs/namei.c @@ -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, -- 1.8.3.1