Skip to content

Commit 566cff0

Browse files
committed
Merge pull request #370 from grissiom/romfs-next
romfs: fix a use-before-set bug on checking the dirent
2 parents 00197fd + 28ff3ed commit 566cff0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

components/dfs/filesystems/romfs/dfs_romfs.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ int dfs_romfs_ioctl(struct dfs_fd *file, int cmd, void *args)
5151

5252
rt_inline int check_dirent(struct romfs_dirent *dirent)
5353
{
54-
if (!(dirent->type == ROMFS_DIRENT_FILE || dirent->type == ROMFS_DIRENT_DIR) ||
55-
(dirent->size == 0 || dirent->size == ~0))
54+
if ((dirent->type != ROMFS_DIRENT_FILE && dirent->type != ROMFS_DIRENT_DIR)
55+
|| dirent->size == ~0)
5656
return -1;
5757
return 0;
5858
}
@@ -191,7 +191,7 @@ int dfs_romfs_open(struct dfs_fd *file)
191191

192192
root_dirent = (struct romfs_dirent *)file->fs->data;
193193

194-
if (check_dirent(dirent) != 0)
194+
if (check_dirent(root_dirent) != 0)
195195
return -DFS_STATUS_EIO;
196196

197197
if (file->flags & (DFS_O_CREAT | DFS_O_WRONLY | DFS_O_APPEND | DFS_O_TRUNC | DFS_O_RDWR))

0 commit comments

Comments
 (0)