diff mbox series

fs: affs: fix a NULL pointer dereference

Message ID 20190315074246.26426-1-kjlu@umn.edu (mailing list archive)
State New, archived
Headers show
Series fs: affs: fix a NULL pointer dereference | expand

Commit Message

Kangjie Lu March 15, 2019, 7:42 a.m. UTC
If affs_bread fails, do not use ext_bh to avoid NULL pointer
 dereference

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 fs/affs/file.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

David Sterba March 21, 2019, 2:45 p.m. UTC | #1
On Fri, Mar 15, 2019 at 02:42:44AM -0500, Kangjie Lu wrote:
> If affs_bread fails, do not use ext_bh to avoid NULL pointer
>  dereference
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>

Tanks for the patch.  I'll need some more time to get familiar with the
AFFS code to review your patch.
diff mbox series

Patch

diff --git a/fs/affs/file.c b/fs/affs/file.c
index a85817f54483..29cbc8eda085 100644
--- a/fs/affs/file.c
+++ b/fs/affs/file.c
@@ -941,8 +941,10 @@  affs_truncate(struct inode *inode)
 		size = AFFS_SB(sb)->s_hashsize;
 		if (size > blkcnt - blk)
 			size = blkcnt - blk;
-		for (i = 0; i < size; i++, blk++)
-			affs_free_block(sb, be32_to_cpu(AFFS_BLOCK(sb, ext_bh, i)));
+		if (ext_bh) {
+			for (i = 0; i < size; i++, blk++)
+				affs_free_block(sb, be32_to_cpu(AFFS_BLOCK(sb, ext_bh, i)));
+		}
 		affs_free_block(sb, ext_key);
 		ext_key = be32_to_cpu(AFFS_TAIL(sb, ext_bh)->extension);
 		affs_brelse(ext_bh);