Skip to content

Commit 8cff69c

Browse files
chaseyuJaegeuk Kim
authored andcommitted
fsck.f2fs: fix to use strncmp to avoid out-of-boundary access
Otherwise, if length of main device path is equal to MAX_PATH_LEN, it will trigger assert() as below: [ASSERT] (init_sb_info:1264) !strcmp((char *)sb->devs[i].path, (char *)c.devices[i].path) This is because there is no null character in the end of devcie path string, result in out-of-boundary access in devs.path[]. Let's use strncmp instead of strcmp to compare device path to fix this issue. Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 47ad82e commit 8cff69c

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

fsck/mount.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,8 +1261,9 @@ int init_sb_info(struct f2fs_sb_info *sbi)
12611261
if (get_device_info(i))
12621262
ASSERT(0);
12631263
} else if (c.func != INJECT) {
1264-
if (strcmp((char *)sb->devs[i].path,
1265-
(char *)c.devices[i].path)) {
1264+
if (strncmp((char *)sb->devs[i].path,
1265+
(char *)c.devices[i].path,
1266+
MAX_PATH_LEN)) {
12661267
MSG(0, "paths mismatch: %s, %s\n",
12671268
(char *)sb->devs[i].path,
12681269
(char *)c.devices[i].path);

0 commit comments

Comments
 (0)