erofs-utils: mkfs: fix an undefined behavior of memcpy
authorGao Xiang <hsiangkao@linux.alibaba.com>
Fri, 6 Sep 2024 08:36:51 +0000 (16:36 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Mon, 9 Sep 2024 04:54:19 +0000 (12:54 +0800)
Call trace:
 - erofs_mkfs_build_tree
  - erofs_mkfs_go(sbi, ~0, NULL, 0);

inode.c:1395:20: runtime error: null pointer passed as argument 2, which is declared to never be null
/usr/include/string.h:44:28: note: nonnull attribute specified here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior inode.c:1395:20 in

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Reviewed-by: Sandeep Dhavale <dhavale@google.com>
Link: https://lore.kernel.org/r/20240906083651.341555-1-hsiangkao@linux.alibaba.com
lib/inode.c

index 128c051712ac584da15357e3e82baefd20052a62..d464bc6fdbd76598be83b701619990836d640af3 100644 (file)
@@ -1392,7 +1392,8 @@ static int erofs_mkfs_go(struct erofs_sb_info *sbi,
 
        item = q->queue + q->tail;
        item->type = type;
-       memcpy(&item->u, elem, size);
+       if (size)
+               memcpy(&item->u, elem, size);
        q->tail = (q->tail + 1) & (q->entries - 1);
        q->idle = false;