Skip to contentSkip to conversation

erofs-utils: mkfs: fix an undefined behavior of memcpy

PATCH In review Gao Xiang 2 participants 2 messages Sep 6, 2024 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 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

---
 lib/inode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/inode.c +2 -1
index 128c051..d464bc6 100644
@@ -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;
 
Signature · 1 line
2.43.5