diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2021-08-22 13:29:26 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2021-08-22 13:44:46 +0200 |
commit | dc694ae0191ed50b7d5aea508e0f5207ba2b452a (patch) | |
tree | f4ef2a82236d8f483cda317c4c3055937db70920 | |
parent | 41c5060e8b980a53edf03b31d1864e17f5309ddb (diff) |
Fix half done initialization of sqfs_dir_reader_open_dir
The sqfs_dir_reader_open_dir function tried to take a short-cut by
returning early if the target directory is empty. However, this left
some field unchanged from the previous directory.
If iterating over a directory and then deciding to enter a sub-directory
that happens to be empty, the directory reader will keep the settings
for the current directory. After calling sqfs_dir_reader_rewind, the
sub-directory will suddenly report the contents of the parent.
A similar check is added to the rewind function to not track back on
the meta data reader in that case.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r-- | lib/sqfs/dir_reader.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/sqfs/dir_reader.c b/lib/sqfs/dir_reader.c index 65962d8..e6467ef 100644 --- a/lib/sqfs/dir_reader.c +++ b/lib/sqfs/dir_reader.c @@ -145,15 +145,15 @@ int sqfs_dir_reader_open_dir(sqfs_dir_reader_t *rd, rd->size = size; rd->entries = 0; - if (rd->size <= sizeof(rd->hdr)) - return 0; - block_start += rd->super->directory_table_start; rd->dir_block_start = block_start; rd->dir_offset = offset; rd->start_size = size; + if (rd->size <= sizeof(rd->hdr)) + return 0; + return sqfs_meta_reader_seek(rd->meta_dir, block_start, offset); } @@ -200,6 +200,9 @@ int sqfs_dir_reader_rewind(sqfs_dir_reader_t *rd) rd->size = rd->start_size; rd->entries = 0; + if (rd->size <= sizeof(rd->hdr)) + return 0; + return sqfs_meta_reader_seek(rd->meta_dir, rd->dir_block_start, rd->dir_offset); } |