Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2259,6 +2259,7 @@ int lfs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data) {
lfs_entry_t entry;
lfs_block_t cwd[2] = {0, 1};

lfs_block_t dirs = 0;
while (true) {
for (int i = 0; i < 2; i++) {
int err = cb(data, cwd[i]);
Expand Down Expand Up @@ -2297,6 +2298,11 @@ int lfs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data) {
if (lfs_pairisnull(cwd)) {
break;
}
if (dirs++ >= lfs->cfg->block_count) {
// If we reached here, we have more directory pairs than blocks in the
// filesystem... So something must be horribly wrong
return LFS_ERR_CORRUPT;
}
}

// iterate over any open files
Expand Down