btrfs-progs: check for fstat failure in cmd_defrag
authorEric Sandeen <sandeen@redhat.com>
Wed, 6 Nov 2013 23:15:53 +0000 (17:15 -0600)
committerChris Mason <chris.mason@fusionio.com>
Thu, 7 Nov 2013 21:10:41 +0000 (16:10 -0500)
Resolves-Coverity-CID: 1125924
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
cmds-filesystem.c

index b4727c27a7ed7a80f82610cbc01f0c0c518435e8..aa361d67dd854339205b9cdbdfa4356812ae04a1 100644 (file)
@@ -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);