fs: check FAT cluster size
PATCH 1/1 fs: check FAT cluster size
The cluster size specifies how many sectors make up a cluster. A cluster size of zero makes no sense, as it would mean that the cluster is made up of no sectors. This will later lead into a division by zero in sect_to_clust(), so better take care of that early.
The MAX_CLUSTSIZE define can reduced using a define to make some room in low-memory system. Unfortunately if the code reads a filesystem with a bigger cluster size it will overflow the buffer.
--- fs/fat/fat.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/fat/fat.c +11 -0
@@ -571,6 +571,17 @@ static int get_fs_info(fsdata *mydata) mydata->sect_size, cur_part_info.blksz);return -1 ; } +if (mydata->clust_size ==0 ) { +printf ("Error: FAT cluster size not set\n" ); +return -1 ; + } +if ((unsigned int )mydata->clust_size * mydata->sect_size > +MAX_CLUSTSIZE ) { +printf ("Error: FAT cluster size too big (cs=%u, max=%u)\n" , + (unsigned int )mydata->clust_size * mydata->sect_size, +MAX_CLUSTSIZE ); +return -1 ; + }if (mydata->fatsize ==32 ) { mydata->data_begin = mydata->rootdir_sect -
Signature · 1 line
2.17.2 (Apple Git-113)
Quoted 11 lines · Patrick Wildt
The cluster size specifies how many sectors make up a cluster. A cluster size of zero makes no sense, as it would mean that the cluster is made up of no sectors. This will later lead into a division by zero in
sect_to_clust(), so better take care of that early.The
MAX_CLUSTSIZEdefine can reduced using a define to make some room in low-memory system. Unfortunately if the code reads a filesystem with a bigger cluster size it will overflow the buffer.Signed-off-by Patrick Wildt <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181207/beadf5ba/attachment.sig>