Skip to content

Commit

Permalink
fs: fat: treat invalid FAT clusters as errors
Browse files Browse the repository at this point in the history
When hitting an invalid FAT cluster while reading a file always print an
error message and return an error code.

Signed-off-by: Heinrich Schuchardt <[email protected]>
  • Loading branch information
xypron authored and trini committed Oct 11, 2019
1 parent ee8da59 commit c7a86d1
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions fs/fat/fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,20 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size)
return 0;
}

/*
/**
* get_contents() - read from file
*
* Read at most 'maxsize' bytes from 'pos' in the file associated with 'dentptr'
* into 'buffer'.
* Update the number of bytes read in *gotsize or return -1 on fatal errors.
* into 'buffer'. Update the number of bytes read in *gotsize or return -1 on
* fatal errors.
*
* @mydata: file system description
* @dentprt: directory entry pointer
* @pos: position from where to read
* @buffer: buffer into which to read
* @maxsize: maximum number of bytes to read
* @gotsize: number of bytes actually read
* Return: -1 on error, otherwise 0
*/
static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos,
__u8 *buffer, loff_t maxsize, loff_t *gotsize)
Expand Down Expand Up @@ -335,8 +345,8 @@ static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos,
curclust = get_fatent(mydata, curclust);
if (CHECK_CLUST(curclust, mydata->fatsize)) {
debug("curclust: 0x%x\n", curclust);
debug("Invalid FAT entry\n");
return 0;
printf("Invalid FAT entry\n");
return -1;
}
actsize += bytesperclust;
}
Expand Down Expand Up @@ -374,8 +384,8 @@ static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos,
curclust = get_fatent(mydata, curclust);
if (CHECK_CLUST(curclust, mydata->fatsize)) {
debug("curclust: 0x%x\n", curclust);
debug("Invalid FAT entry\n");
return 0;
printf("Invalid FAT entry\n");
return -1;
}
}

Expand All @@ -390,8 +400,8 @@ static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos,
goto getit;
if (CHECK_CLUST(newclust, mydata->fatsize)) {
debug("curclust: 0x%x\n", newclust);
debug("Invalid FAT entry\n");
return 0;
printf("Invalid FAT entry\n");
return -1;
}
endclust = newclust;
actsize += bytesperclust;
Expand All @@ -418,7 +428,7 @@ static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos,
if (CHECK_CLUST(curclust, mydata->fatsize)) {
debug("curclust: 0x%x\n", curclust);
printf("Invalid FAT entry\n");
return 0;
return -1;
}
actsize = bytesperclust;
endclust = curclust;
Expand Down

0 comments on commit c7a86d1

Please sign in to comment.