diff options
author | Maxim Korotkov <korotkov.maxim.s@gmail.com> | 2023-06-02 13:26:07 +0300 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2023-06-07 09:57:30 -0700 |
commit | 2eaf825fc460005cf61508e42530b36cbb3bc881 (patch) | |
tree | 192ae6cc0d23b855e596eed676cf17f5193284db | |
parent | 7933e522c9df1d0bc5a7da8431554c749c0eea52 (diff) | |
download | f2fs-tools-2eaf825fc460005cf61508e42530b36cbb3bc881.tar.gz |
fsck.f2fs: fix potential NULL dereference
The input pointer "parent" was used unsafely
before checking against NULL
Found by RASU JSC with Svace static analyzer
Fixes: 603f8f9d3(sload.f2fs: support loading files into partition directly)
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Maxim Korotkov <maskorotkov@rasu.ru>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r-- | fsck/dir.c | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -225,19 +225,23 @@ int f2fs_add_link(struct f2fs_sb_info *sbi, struct f2fs_node *parent, int level = 0, current_depth, bit_pos; int nbucket, nblock, bidx, block; int slots = GET_DENTRY_SLOTS(name_len); - f2fs_hash_t dentry_hash = f2fs_dentry_hash(get_encoding(sbi), - IS_CASEFOLDED(&parent->i), - name, name_len); + f2fs_hash_t dentry_hash; struct f2fs_dentry_block *dentry_blk; struct f2fs_dentry_ptr d; struct dnode_of_data dn; - nid_t pino = le32_to_cpu(parent->footer.ino); - unsigned int dir_level = parent->i.i_dir_level; + nid_t pino; + unsigned int dir_level; int ret; if (parent == NULL) return -EINVAL; + dentry_hash = f2fs_dentry_hash(get_encoding(sbi), + IS_CASEFOLDED(&parent->i), + name, name_len); + pino = le32_to_cpu(parent->footer.ino); + dir_level = parent->i.i_dir_level; + if (!pino) { ERR_MSG("Wrong parent ino:%d \n", pino); return -EINVAL; |