]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
fs: ext4: Prevent infinite loop in ext4fs_iterate_dir
authorThomas Fitzsimmons <fitzsim@cisco.com>
Wed, 18 Nov 2015 17:42:53 +0000 (12:42 -0500)
committerTom Rini <trini@konsulko.com>
Mon, 23 Nov 2015 16:01:52 +0000 (11:01 -0500)
If the ext3 journal gets out of sync with what is written on disk, for
example because of an unexpected power cut, ext4fs_read_file can
return an all-zero directory entry.  In that case, ext4fs_iterate_dir
would infinite loop.

This patch detects when a directory entry's direntlen member is 0 and
returns a failure status, which breaks out of the infinite loop.  As a
result, U-Boot will not find files that may subsequently be recovered
when the journal is replayed.

This is better behaviour than hanging in an infinite loop, but as a
further improvement maybe U-Boot could interpret the ext3 journal and
actually find the unsynced entries.

Signed-off-by: Thomas Fitzsimmons <fitzsim@cisco.com>
Reviewed-by: Stefan Roese <sr@denx.de>
fs/ext4/ext4_common.c

index 727a2f753df391457010925aa237a46330b5cf5f..e73223ac22c99a8687d065e5f91732f7f6deab98 100644 (file)
@@ -1920,6 +1920,11 @@ int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name,
                if (status < 0)
                        return 0;
 
+               if (dirent.direntlen == 0) {
+                       printf("Failed to iterate over directory %s\n", name);
+                       return 0;
+               }
+
                if (dirent.namelen != 0) {
                        char filename[dirent.namelen + 1];
                        struct ext2fs_node *fdiro;