From 971fe056305c7f57629d609490701e13298e658b Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Thu, 29 Mar 2007 00:32:23 -0400 Subject: [PATCH] [COVERITY] Handle potential case in debugfs if ext2fs_get_pathname returns NULL Coverity ID: 51: Use After Free Signed-off-by: Brian Behlendorf --- debugfs/ChangeLog | 3 +++ debugfs/debugfs.c | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/debugfs/ChangeLog b/debugfs/ChangeLog index c49aa63..d6fd671 100644 --- a/debugfs/ChangeLog +++ b/debugfs/ChangeLog @@ -1,5 +1,8 @@ 2007-03-29 Theodore Tso + * debugfs.c (do_print_working_directory): Handle the case if + ext2fs_get_pathname returns NULL for the pathname. + * htree.c (do_htree_dump): Fix coverity use before assignment warning. (long_opt isn't being used for anything right now, so this is a no-op) diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c index 3bddef9..5efeb07 100644 --- a/debugfs/debugfs.c +++ b/debugfs/debugfs.c @@ -953,15 +953,23 @@ void do_print_working_directory(int argc, char *argv[]) com_err(argv[0], retval, "while trying to get pathname of cwd"); } - printf("[pwd] INODE: %6u PATH: %s\n", cwd, pathname); - free(pathname); + printf("[pwd] INODE: %6u PATH: %s\n", + cwd, pathname ? pathname : "NULL"); + if (pathname) { + free(pathname); + pathname = NULL; + } retval = ext2fs_get_pathname(current_fs, root, 0, &pathname); if (retval) { com_err(argv[0], retval, "while trying to get pathname of root"); } - printf("[root] INODE: %6u PATH: %s\n", root, pathname); - free(pathname); + printf("[root] INODE: %6u PATH: %s\n", + root, pathname ? pathname : "NULL"); + if (pathname) { + free(pathname); + pathname = NULL; + } return; } -- 1.8.3.1