]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
efi_selftest: fix ESRT creation tests
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Tue, 8 Jul 2025 11:37:32 +0000 (13:37 +0200)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sat, 26 Jul 2025 05:37:03 +0000 (07:37 +0200)
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: 4ac6041c3cbf ("efi: ESRT creation tests")
Addresses-Coverity-ID: CID 569497: Null pointer dereferences (FORWARD_NULL)
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
lib/efi_selftest/efi_selftest_esrt.c

index b7688deb4964384e42274d844be166d40860288a..7eadac90fbcba606da18942199a8581dc7551f76 100644 (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];