* [PATCH] fat: add a check to fat_add_new_entries
@ 2020-06-16 16:29 trix
2020-06-21 17:50 ` OGAWA Hirofumi
0 siblings, 1 reply; 2+ messages in thread
From: trix @ 2020-06-16 16:29 UTC (permalink / raw)
To: hirofumi; +Cc: linux-kernel, Tom Rix
From: Tom Rix <trix@redhat.com>
Clang static analysis reports a possible null pointer dereference
fs/fat/dir.c:1255:9: warning: Dereference of undefined pointer value [core.NullDereference]
memset(bhs[n]->b_data + copy, 0, sb->s_blocksize - copy);
^~~~~~~~~~~~~~
This is because setting of bhs[n] depends on the inner loop executing.
So add a check that the inner loop will be executed.
Signed-off-by: Tom Rix <trix@redhat.com>
---
fs/fat/dir.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index b4ddf48fa444..3eea540486cb 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -1228,6 +1228,13 @@ static int fat_add_new_entries(struct inode *dir, void *slots, int nr_slots,
do {
start_blknr = blknr = fat_clus_to_blknr(sbi, cluster[i]);
last_blknr = start_blknr + sbi->sec_per_clus;
+
+ /* overflow */
+ if (unlikely(last_blknr <= start_blknr)) {
+ err = -ENOMEM;
+ goto error_nomem;
+ }
+
while (blknr < last_blknr) {
bhs[n] = sb_getblk(sb, blknr);
if (!bhs[n]) {
--
2.18.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-21 17:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-16 16:29 [PATCH] fat: add a check to fat_add_new_entries trix
2020-06-21 17:50 ` OGAWA Hirofumi
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.