From b68477aee114470bde87d655ef647f8475b18003 Mon Sep 17 00:00:00 2001 From: Eric Sandeen Date: Wed, 6 Nov 2013 17:15:53 -0600 Subject: [PATCH] btrfs-progs: check for fstat failure in cmd_defrag Resolves-Coverity-CID: 1125924 Signed-off-by: Eric Sandeen Signed-off-by: Chris Mason --- cmds-filesystem.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index b4727c27..aa361d67 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -681,7 +681,13 @@ static int cmd_defrag(int argc, char **argv) if (recursive) { struct stat st; - fstat(fd, &st); + if (fstat(fd, &st)) { + fprintf(stderr, "ERROR: failed to stat %s - %s\n", + argv[i], strerror(errno)); + defrag_global_errors++; + close_file_or_dir(fd, dirstream); + continue; + } if (S_ISDIR(st.st_mode)) { ret = nftw(argv[i], defrag_callback, 10, FTW_MOUNT | FTW_PHYS);