From ff1ca05f60f731b038b9a2515be5c6022f54fb05 Mon Sep 17 00:00:00 2001 From: Gao Xiang Date: Fri, 6 Sep 2024 16:36:51 +0800 Subject: [PATCH] erofs-utils: mkfs: fix an undefined behavior of memcpy 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 Reviewed-by: Sandeep Dhavale Link: https://lore.kernel.org/r/20240906083651.341555-1-hsiangkao@linux.alibaba.com --- lib/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/inode.c b/lib/inode.c index 128c051..d464bc6 100644 --- a/lib/inode.c +++ b/lib/inode.c @@ -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; -- 2.34.1