Message ID | 20201031010752.23974-2-wqu@suse.com |
---|---|
State | Accepted |
Commit | 9b5546c37ab020039f06855eae28fbd56adb096b |
Delegated to: | Tom Rini |
Headers | show |
Series | fs: btrfs: coverity fixes | expand |
Reviewed-by: Marek Behún <marek.behun@nic.cz>
On Sat, Oct 31, 2020 at 09:07:49AM +0800, Qu Wenruo wrote: > 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> > Reviewed-by: Marek Behún <marek.behun@nic.cz> Applied to u-boot/master, thanks!
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;
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(-)