public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: u-boot@lists.denx.de
Subject: [PATCH 1/4] fs: btrfs: inode: handle uninitialized type before returning it
Date: Sat, 31 Oct 2020 09:07:49 +0800	[thread overview]
Message-ID: <20201031010752.23974-2-wqu@suse.com> (raw)
In-Reply-To: <20201031010752.23974-1-wqu@suse.com>

In btrfs_lookup_path() the local variable @type should always be updated
after we hit any file/dir.

But if @filename is NULL from the very beginning, then we don't
initialize it and return it directly.

To prevent such problem from happening, we initialize @type to
BTRFS_FT_UNKNOWN.
For normal execution route, it will get updated for each filename we
resolved.
Buf if we didn't find any path, we check if the type is still FT_UNKNOWN
and ret == 0. If true we know there is something wrong, just return
-EUCLEAN to inform the caller.

Reported-by: Coverity CID 312958
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/inode.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index ff330280e025..019d532a1a4b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -251,7 +251,7 @@ int btrfs_lookup_path(struct btrfs_root *root, u64 ino, const char *filename,
 	const char *cur = filename;
 	u64 next_ino;
 	u8 next_type;
-	u8 type;
+	u8 type = BTRFS_FT_UNKNOWN;
 	int len;
 	int ret = 0;
 
@@ -335,6 +335,10 @@ next:
 		cur += len;
 	}
 
+	/* We haven't found anything, but still get no error? */
+	if (type == BTRFS_FT_UNKNOWN && !ret)
+		ret = -EUCLEAN;
+
 	if (!ret) {
 		*root_ret = root;
 		*ino_ret = ino;
-- 
2.29.1

  reply	other threads:[~2020-10-31  1:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-31  1:07 [PATCH 0/4] fs: btrfs: coverity fixes Qu Wenruo
2020-10-31  1:07 ` Qu Wenruo [this message]
2020-11-01 22:59   ` [PATCH 1/4] fs: btrfs: inode: handle uninitialized type before returning it Marek Behun
2020-11-20  1:36   ` Tom Rini
2020-10-31  1:07 ` [PATCH 2/4] fs: btrfs: volumes: prevent overflow for multiplying Qu Wenruo
2020-11-01 23:02   ` Marek Behun
2020-11-02  0:20     ` Qu Wenruo
2020-11-02  1:06       ` Qu Wenruo
2021-01-20 21:46   ` Tom Rini
2020-10-31  1:07 ` [PATCH 3/4] fs: btrfs: initialize @ret to 0 to prevent uninitialized return value Qu Wenruo
2020-11-01 23:03   ` Marek Behun
2020-11-20  1:36   ` Tom Rini
2020-10-31  1:07 ` [PATCH 4/4] fs: btrfs: initialize @ii in show_dir() to make coverity happy Qu Wenruo
2020-11-01 23:06   ` Marek Behun
2020-11-02  0:27     ` Qu Wenruo
2020-11-02  7:24       ` Marek Behun
2020-11-02  7:27         ` Qu Wenruo
2020-11-02 20:17         ` Tom Rini

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=20201031010752.23974-2-wqu@suse.com \
    --to=wqu@suse.com \
    --cc=u-boot@lists.denx.de \
    /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