fs/sfs: Fix error check and add sanity check.

Found by: Coverity scan.
This commit is contained in:
Vladimir Serbinenko 2015-01-25 13:33:03 +01:00
parent 8c1d086689
commit 66baeffc0f

View file

@ -173,10 +173,11 @@ grub_sfs_read_extent (struct grub_sfs_data *data, unsigned int block,
struct grub_sfs_btree *tree; struct grub_sfs_btree *tree;
int i; int i;
grub_uint32_t next; grub_uint32_t next;
grub_size_t blocksize = GRUB_DISK_SECTOR_SIZE << data->log_blocksize;
treeblock = grub_malloc (GRUB_DISK_SECTOR_SIZE << data->log_blocksize); treeblock = grub_malloc (blocksize);
if (!block) if (!treeblock)
return 0; return grub_errno;
next = grub_be_to_cpu32 (data->rblock.btree); next = grub_be_to_cpu32 (data->rblock.btree);
tree = (struct grub_sfs_btree *) treeblock; tree = (struct grub_sfs_btree *) treeblock;
@ -184,17 +185,21 @@ grub_sfs_read_extent (struct grub_sfs_data *data, unsigned int block,
/* Handle this level in the btree. */ /* Handle this level in the btree. */
do do
{ {
grub_uint16_t nnodes;
grub_disk_read (data->disk, grub_disk_read (data->disk,
((grub_disk_addr_t) next) << data->log_blocksize, ((grub_disk_addr_t) next) << data->log_blocksize,
0, GRUB_DISK_SECTOR_SIZE << data->log_blocksize, 0, blocksize, treeblock);
treeblock);
if (grub_errno) if (grub_errno)
{ {
grub_free (treeblock); grub_free (treeblock);
return grub_errno; return grub_errno;
} }
for (i = grub_be_to_cpu16 (tree->nodes) - 1; i >= 0; i--) nnodes = grub_be_to_cpu16 (tree->nodes);
if (nnodes * (grub_uint32_t) (tree)->nodesize > blocksize)
break;
for (i = (int) nnodes - 1; i >= 0; i--)
{ {
#define EXTNODE(tree, index) \ #define EXTNODE(tree, index) \