efi_selftest: fix ESRT creation tests

The code foresees that parameters descriptor_size and descriptor_count
might be NULL and then dereferences them without further check.

The size check must take into account the descriptor count.

ImageInfo might be NULL. In this case we must not dereference it.

Fixes: 4ac6041c3c ("efi: ESRT creation tests")
Addresses-Coverity-ID: CID 569497: Null pointer dereferences (FORWARD_NULL)
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
This commit is contained in:
Heinrich Schuchardt
2025-07-08 13:37:32 +02:00
parent 7e2506e3a2
commit ca01c847f6

View File

@@ -69,10 +69,12 @@ EFIAPI efi_test_fmp_get_image_info(struct efi_firmware_management_protocol *this
if (package_version_name)
*package_version_name = NULL;
if (*image_info_size < sizeof(*image_info)) {
*image_info_size = *descriptor_size * *descriptor_count;
if (*image_info_size < sizeof(*image_info) * TEST_ESRT_NUM_ENTRIES) {
*image_info_size = sizeof(*image_info) * TEST_ESRT_NUM_ENTRIES;
return EFI_BUFFER_TOO_SMALL;
}
if (!image_info)
return EFI_INVALID_PARAMETER;
for (int idx = 0; idx < TEST_ESRT_NUM_ENTRIES; idx++)
image_info[idx] = static_img_info[idx];