Skip to contentSkip to conversation

fs/squashfs: parameter check sqfs_read_metablock()

PATCH New Heinrich Schuchardt 3 participants 4 messages Sep 23, 2020 – Sep 30, 2020 SquashFS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/squashfs: parameter check sqfs_read_metablock()

We should check if the incoming parameter file_mapping is not NULL instead of checking after adding an offset.

Reported-by Coverity CID 307210
---
 fs/squashfs/sqfs_inode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/squashfs/sqfs_inode.c +2 -2
index 1368f3063c..14d70cf678 100644
@@ -141,9 +141,9 @@ int sqfs_read_metablock(unsigned char *file_mapping, int offset,
 	const unsigned char *data;
 	u16 header;
 
-	data = file_mapping + offset;
-	if (!data)
+	if (!file_mapping)
 		return -EFAULT;
+	data = file_mapping + offset;
 
 	header = get_unaligned((u16 *)data);
 	if (!header)

--
2.28.0

#1 lore raw

PATCH 1/1 fs/squashfs: parameter check sqfs_read_metablock()

Quoted 5 lines · On Wed, 23 Sep 2020 21:13:51 +0200 Heinrich Schuchardt <[email protected]>…

We should check if the incoming parameter file_mapping is not NULL instead of checking after adding an offset.

Reported-by Coverity CID 307210

However, I wonder if this check is really useful. sqfs_read_metablock() is an internal function, so it should be up to the callers to make sure that they don't pass a NULL file_mapping argument.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw

PATCH 1/1 fs/squashfs: parameter check sqfs_read_metablock()

Quoted 9 lines · Thomas Petazzoni
Quoted 5 lines · On Wed, 23 Sep 2020 21:13:51 +0200 Heinrich Schuchardt <[email protected]>…

We should check if the incoming parameter file_mapping is not NULL instead of checking after adding an offset.

Reported-by Coverity CID 307210
Quoted 8 lines

However, I wonder if this check is really useful. sqfs_read_metablock() is an internal function, so it should be up to the callers to make sure that they don't pass a NULL file_mapping argument.

Thomas

This is a question of programming style. Eliminating the check may be justified if the input variable is checked by every caller.

The real problems are elsewhere, e.g.

sqfs_search_dir() and sqfs_readdir() do not check the return value of sqfs_find_inode() which may be NULL.

sqfs_opendir() leaks allocated memory if an error occurs.

Best regards

Heinrich

#3 lore raw

PATCH 1/1 fs/squashfs: parameter check sqfs_read_metablock()

In reply to Heinrich Schuchardt
Quoted 6 lines · Heinrich Schuchardt

We should check if the incoming parameter file_mapping is not NULL instead of checking after adding an offset.

Reported-by Coverity CID 307210

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: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200930/a11ced17/attachment.sig>