[PATCH] fs/jffs2: Fix potential NULL dereference in jffs2_add_frag_to_fragtree()

From: Haowen Bai
Date: Fri Apr 01 2022 - 03:23:38 EST


this could be null, so we need to checking null before dereference

Signed-off-by: Haowen Bai <baihaowen@xxxxxxxxx>
---
fs/jffs2/nodelist.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/jffs2/nodelist.c b/fs/jffs2/nodelist.c
index b86c78d178c6..ed3b3b25bfab 100644
--- a/fs/jffs2/nodelist.c
+++ b/fs/jffs2/nodelist.c
@@ -246,7 +246,7 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *r
return no_overlapping_node(c, root, newfrag, this, lastend);
}

- if (this->node)
+ if (this && this->node)
dbg_fragtree2("dealing with frag %u-%u, phys %#08x(%d).\n",
this->ofs, this->ofs + this->size,
ref_offset(this->node->raw), ref_flags(this->node->raw));
--
2.7.4