dissect-image: reject empty partitions array

di is allocated while iterating over p.partitions. If the array is
empty,
the loop is skipped and di remains NULL, but the code still assigns
image
metadata through it.

Return EBADMSG before accessing di in this case.

Found by Linux Verification Center (linuxtesting.org) with Svace.
This commit is contained in:
Mikhail Nogin
2026-05-26 17:53:27 +09:00
committed by Yu Watanabe
parent 6f5100bf12
commit d096763827
+3
View File
@@ -5298,6 +5298,9 @@ int mountfsd_mount_image_fd(
};
}
if (!di)
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG), "Partition list is empty.");
di->single_file_system = p.single_file_system;
di->image_size = p.image_size;
di->sector_size = p.sector_size;