fsck.f2fs: fix potential overflow of copying i_name

If i_namelen is corrupted, there may be an overflow when doing memcpy.

Signed-off-by: Sheng Yong <shengyong@oppo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Sheng Yong 2022-11-10 22:07:22 +08:00 committed by sunshenshen
parent e9217c4777
commit 792c0b4a71

View File

@ -742,8 +742,10 @@ check_next:
if (ftype == F2FS_FT_DIR) { if (ftype == F2FS_FT_DIR) {
f2fs_set_main_bitmap(sbi, ni->blk_addr, CURSEG_HOT_NODE); f2fs_set_main_bitmap(sbi, ni->blk_addr, CURSEG_HOT_NODE);
memcpy(child.p_name, node_blk->i.i_name, namelen = le32_to_cpu(node_blk->i.i_namelen);
node_blk->i.i_namelen); if (namelen > F2FS_NAME_LEN)
namelen = F2FS_NAME_LEN;
memcpy(child.p_name, node_blk->i.i_name, namelen);
} else { } else {
if (f2fs_test_main_bitmap(sbi, ni->blk_addr) == 0) { if (f2fs_test_main_bitmap(sbi, ni->blk_addr) == 0) {
f2fs_set_main_bitmap(sbi, ni->blk_addr, f2fs_set_main_bitmap(sbi, ni->blk_addr,