lkml.org 
[lkml]   [2016]   [Dec]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] btrfs: fix dereference on inode->i_sb before inode null check
Date
From: Colin Ian King <colin.king@canonical.com>

inode is being deferenced and then inode is checked to see if it
is null, implying we potentially could have a null pointer deference
on inode.

Found with static analysis by CoverityScan, CID 1389472

Fix this by dereferencing inode only after the inode null check.

Fixes: 0b246afa62b0cf5 ("btrfs: root->fs_info cleanup, add fs_info convenience variables")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
fs/btrfs/export.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/export.c b/fs/btrfs/export.c
index 340d907..b746d2b 100644
--- a/fs/btrfs/export.c
+++ b/fs/btrfs/export.c
@@ -223,7 +223,7 @@ static int btrfs_get_name(struct dentry *parent, char *name,
{
struct inode *inode = d_inode(child);
struct inode *dir = d_inode(parent);
- struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
+ struct btrfs_fs_info *fs_info;
struct btrfs_path *path;
struct btrfs_root *root = BTRFS_I(dir)->root;
struct btrfs_inode_ref *iref;
@@ -241,6 +241,7 @@ static int btrfs_get_name(struct dentry *parent, char *name,
if (!S_ISDIR(dir->i_mode))
return -EINVAL;

+ fs_info = btrfs_sb(inode->i_sb);
ino = btrfs_ino(inode);

path = btrfs_alloc_path();
--
2.10.2
\
 
 \ /
  Last update: 2016-12-16 13:22    [W:0.568 / U:0.068 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site