From mboxrd@z Thu Jan 1 00:00:00 1970 From: Chao Yu Subject: Re: [PATCH v2] fsck.f2fs: check nid range before use to avoid segmentation fault Date: Sat, 23 Dec 2017 11:14:07 +0800 Message-ID: References: <1513319174-114303-1-git-send-email-yunlong.song@huawei.com> <1513598025-160615-1-git-send-email-yunlong.song@huawei.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from sfi-mx-4.v28.ch3.sourceforge.com ([172.29.28.194] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eSaGV-0003Yn-Rg for linux-f2fs-devel@lists.sourceforge.net; Sat, 23 Dec 2017 03:14:23 +0000 Received: from [45.249.212.35] (helo=huawei.com) by sfi-mx-4.v28.ch3.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) id 1eSaGU-0000nA-Bi for linux-f2fs-devel@lists.sourceforge.net; Sat, 23 Dec 2017 03:14:23 +0000 In-Reply-To: <1513598025-160615-1-git-send-email-yunlong.song@huawei.com> Content-Language: en-US List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net To: Yunlong Song , jaegeuk@kernel.org, chao@kernel.org, yunlong.song@icloud.com Cc: shengyong1@huawei.com, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, heyunlei@huawei.com, linux-fsdevel@vger.kernel.org, miaoxie@huawei.com On 2017/12/18 19:53, Yunlong Song wrote: > Signed-off-by: Yunlong Song How about introducing IS_AVAILABLE_NID as below, and use it instead? #define IS_AVAILABLE_NID(sbi, nid) (IS_VALID_NID(sbi, nid) && (nid >= root_ino)) Thanks, > --- > fsck/fsck.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fsck/fsck.c b/fsck/fsck.c > index 11b8b0b..faf0663 100644 > --- a/fsck/fsck.c > +++ b/fsck/fsck.c > @@ -740,7 +740,7 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid, > for (idx = 0; idx < 5; idx++) { > u32 nid = le32_to_cpu(node_blk->i.i_nid[idx]); > > - if (nid != 0) { > + if (nid != 0 && IS_VALID_NID(sbi, nid)) { > struct node_info ni; > > get_node_info(sbi, nid, &ni); > ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot