Skip to content

Commit

Permalink
Make error handling in find_slot() more robust.
Browse files Browse the repository at this point in the history
check_slot() can potentially return any value besides 0, -EIO and
-EINVAL.
  • Loading branch information
relan committed Oct 9, 2021
1 parent f826fee commit ac4253d
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions libexfat/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -858,21 +858,22 @@ static int find_slot(struct exfat* ef, struct exfat_node* dir,
if (contiguous++ == 0)
*offset = (off_t) i * sizeof(struct exfat_entry);
if (contiguous == n)
{
int rc;

/* suitable slot is found, check that it's not occupied */
switch (check_slot(ef, dir, *offset, n))
rc = check_slot(ef, dir, *offset, n);
if (rc == -EINVAL)
{
case 0:
free(dmap);
return 0;
case -EIO:
free(dmap);
return -EIO;
case -EINVAL:
/* slot at (i-n) is occupied, go back and check (i-n+1) */
i -= contiguous - 1;
contiguous = 0;
break;
} else {
/* slot is free or an error occurred */
free(dmap);
return rc;
}
}
}
else
contiguous = 0;
Expand Down

0 comments on commit ac4253d

Please sign in to comment.