Skip to content

Commit ac4253d

Browse files
committed
Make error handling in find_slot() more robust.
check_slot() can potentially return any value besides 0, -EIO and -EINVAL.
1 parent f826fee commit ac4253d

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

libexfat/node.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -858,21 +858,22 @@ static int find_slot(struct exfat* ef, struct exfat_node* dir,
858858
if (contiguous++ == 0)
859859
*offset = (off_t) i * sizeof(struct exfat_entry);
860860
if (contiguous == n)
861+
{
862+
int rc;
863+
861864
/* suitable slot is found, check that it's not occupied */
862-
switch (check_slot(ef, dir, *offset, n))
865+
rc = check_slot(ef, dir, *offset, n);
866+
if (rc == -EINVAL)
863867
{
864-
case 0:
865-
free(dmap);
866-
return 0;
867-
case -EIO:
868-
free(dmap);
869-
return -EIO;
870-
case -EINVAL:
871868
/* slot at (i-n) is occupied, go back and check (i-n+1) */
872869
i -= contiguous - 1;
873870
contiguous = 0;
874-
break;
871+
} else {
872+
/* slot is free or an error occurred */
873+
free(dmap);
874+
return rc;
875875
}
876+
}
876877
}
877878
else
878879
contiguous = 0;

0 commit comments

Comments
 (0)