linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Maxim Korotkov <korotkov.maxim.s@gmail.com>
To: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Maxim Korotkov <maskorotkov@rasu.ru>,
	Maxim Korotkov <korotkov.maxim.s@gmail.com>,
	linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH] fsck.f2fs: fix potential NULL dereference
Date: Wed, 31 May 2023 09:51:42 +0300	[thread overview]
Message-ID: <20230531065142.365199-1-korotkov.maxim.s@gmail.com> (raw)

The input pointer "parent" was used unsafely
before checking against NULL

Found by RASU JSC with Svace static analyzer
Fixes: 603f8f9d3(sload.f2fs: support loading files into partition directly)
Signed-off-by: Maxim Korotkov <maskorotkov@rasu.ru>
---
 fsck/dir.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/fsck/dir.c b/fsck/dir.c
index 4a3eb6e..925fe14 100644
--- a/fsck/dir.c
+++ b/fsck/dir.c
@@ -225,19 +225,23 @@ int f2fs_add_link(struct f2fs_sb_info *sbi, struct f2fs_node *parent,
 	int level = 0, current_depth, bit_pos;
 	int nbucket, nblock, bidx, block;
 	int slots = GET_DENTRY_SLOTS(name_len);
-	f2fs_hash_t dentry_hash = f2fs_dentry_hash(get_encoding(sbi),
-						IS_CASEFOLDED(&parent->i),
-						name, name_len);
+	f2fs_hash_t dentry_hash;
 	struct f2fs_dentry_block *dentry_blk;
 	struct f2fs_dentry_ptr d;
 	struct dnode_of_data dn;
-	nid_t pino = le32_to_cpu(parent->footer.ino);
-	unsigned int dir_level = parent->i.i_dir_level;
+	nid_t pino;
+	unsigned int dir_level;
 	int ret;
 
 	if (parent == NULL)
 		return -EINVAL;
 
+	dentry_hash = f2fs_dentry_hash(get_encoding(sbi),
+						IS_CASEFOLDED(&parent->i),
+						name, name_len);	
+	pino = le32_to_cpu(parent->footer.ino);
+	dir_level = parent->i.i_dir_level;
+
 	if (!pino) {
 		ERR_MSG("Wrong parent ino:%d \n", pino);
 		return -EINVAL;
-- 
2.34.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

             reply	other threads:[~2023-05-31  6:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-31  6:51 Maxim Korotkov [this message]
2023-06-02  9:38 ` [f2fs-dev] [PATCH] fsck.f2fs: fix potential NULL dereference Chao Yu

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=20230531065142.365199-1-korotkov.maxim.s@gmail.com \
    --to=korotkov.maxim.s@gmail.com \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=maskorotkov@rasu.ru \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).