From: trix@redhat.com
To: hirofumi@mail.parknet.co.jp
Cc: linux-kernel@vger.kernel.org, Tom Rix <trix@redhat.com>
Subject: [PATCH] fat: add a check to fat_add_new_entries
Date: Tue, 16 Jun 2020 09:29:22 -0700 [thread overview]
Message-ID: <20200616162922.26168-1-trix@redhat.com> (raw)
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
next reply other threads:[~2020-06-16 16:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-16 16:29 trix [this message]
2020-06-21 17:50 ` [PATCH] fat: add a check to fat_add_new_entries OGAWA Hirofumi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200616162922.26168-1-trix@redhat.com \
--to=trix@redhat.com \
--cc=hirofumi@mail.parknet.co.jp \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.