* [PATCH 1/1] fs/squashfs: parameter check sqfs_read_metablock()
@ 2020-09-23 19:13 Heinrich Schuchardt
2020-09-23 19:49 ` Thomas Petazzoni
2020-09-30 12:50 ` Tom Rini
0 siblings, 2 replies; 4+ messages in thread
From: Heinrich Schuchardt @ 2020-09-23 19:13 UTC (permalink / raw)
To: u-boot
We should check if the incoming parameter file_mapping is not NULL instead
of checking after adding an offset.
Reported-by: Coverity CID 307210
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
fs/squashfs/sqfs_inode.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/squashfs/sqfs_inode.c b/fs/squashfs/sqfs_inode.c
index 1368f3063c..14d70cf678 100644
--- a/fs/squashfs/sqfs_inode.c
+++ b/fs/squashfs/sqfs_inode.c
@@ -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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 1/1] fs/squashfs: parameter check sqfs_read_metablock()
2020-09-23 19:13 [PATCH 1/1] fs/squashfs: parameter check sqfs_read_metablock() Heinrich Schuchardt
@ 2020-09-23 19:49 ` Thomas Petazzoni
2020-09-23 20:36 ` Heinrich Schuchardt
2020-09-30 12:50 ` Tom Rini
1 sibling, 1 reply; 4+ messages in thread
From: Thomas Petazzoni @ 2020-09-23 19:49 UTC (permalink / raw)
To: u-boot
On Wed, 23 Sep 2020 21:13:51 +0200
Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> We should check if the incoming parameter file_mapping is not NULL instead
> of checking after adding an offset.
>
> Reported-by: Coverity CID 307210
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
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
--
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/1] fs/squashfs: parameter check sqfs_read_metablock()
2020-09-23 19:49 ` Thomas Petazzoni
@ 2020-09-23 20:36 ` Heinrich Schuchardt
0 siblings, 0 replies; 4+ messages in thread
From: Heinrich Schuchardt @ 2020-09-23 20:36 UTC (permalink / raw)
To: u-boot
On 9/23/20 9:49 PM, Thomas Petazzoni wrote:
> On Wed, 23 Sep 2020 21:13:51 +0200
> Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
>> We should check if the incoming parameter file_mapping is not NULL instead
>> of checking after adding an offset.
>>
>> Reported-by: Coverity CID 307210
>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>
> Acked-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
>
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/1] fs/squashfs: parameter check sqfs_read_metablock()
2020-09-23 19:13 [PATCH 1/1] fs/squashfs: parameter check sqfs_read_metablock() Heinrich Schuchardt
2020-09-23 19:49 ` Thomas Petazzoni
@ 2020-09-30 12:50 ` Tom Rini
1 sibling, 0 replies; 4+ messages in thread
From: Tom Rini @ 2020-09-30 12:50 UTC (permalink / raw)
To: u-boot
On Wed, Sep 23, 2020 at 09:13:51PM +0200, Heinrich Schuchardt wrote:
> We should check if the incoming parameter file_mapping is not NULL instead
> of checking after adding an offset.
>
> Reported-by: Coverity CID 307210
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Acked-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Applied to u-boot/master, thanks!
--
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>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-09-30 12:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-23 19:13 [PATCH 1/1] fs/squashfs: parameter check sqfs_read_metablock() Heinrich Schuchardt
2020-09-23 19:49 ` Thomas Petazzoni
2020-09-23 20:36 ` Heinrich Schuchardt
2020-09-30 12:50 ` Tom Rini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.