Skip to content

Commit

Permalink
ext2: Fix _ext2_dir_read() skipping last entries in a directory
Browse files Browse the repository at this point in the history
  • Loading branch information
astalke committed Jan 24, 2023
1 parent 73b4f1b commit d5f8d30
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ext2/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,14 @@ int _ext2_dir_read(ext2_t *fs, ext2_obj_t *dir, offs_t offs, struct dirent *res,
if ((entry = (ext2_dirent_t *)malloc(len)) == NULL)
return -ENOMEM;

if ((ret = _ext2_file_read(fs, dir, offs, (char *)entry, len)) != len) {
if ((ret = _ext2_file_read(fs, dir, offs, (char *)entry, len)) < 0) {
free(entry);
return (ret < 0) ? (int)ret : -ENOENT;
return ret;
}

if (((size_t)ret < sizeof(ext2_dirent_t)) || ((size_t)ret < sizeof(ext2_dirent_t) + entry->len)) {
free(entry);
return -ENOENT;
}

if (!entry->len) {
Expand Down

0 comments on commit d5f8d30

Please sign in to comment.