]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_loader: check efi_get_variable_int return value
authorMasahisa Kojima <masahisa.kojima@linaro.org>
Mon, 29 Jan 2024 02:51:14 +0000 (11:51 +0900)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Mon, 29 Jan 2024 10:31:44 +0000 (11:31 +0100)
efi_get_variable_int() may fail, the buffer should be
cleared before using it.

Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
Addresses-Coverity-ID: 478333 ("Error handling issues")

lib/efi_loader/efi_firmware.c

index 9fd13297a60d22c7999a15883d710ae4d213faa3..ba5aba098c0fcac04b5ecb46c76627953c4b6381 100644 (file)
@@ -400,18 +400,18 @@ efi_status_t efi_firmware_set_fmp_state_var(struct fmp_state *state, u8 image_in
        }
 
        size = num_banks * sizeof(*var_state);
-       var_state = calloc(1, size);
+       var_state = malloc(size);
        if (!var_state)
                return EFI_OUT_OF_RESOURCES;
 
        /*
         * GetVariable may fail, EFI_NOT_FOUND is returned if FmpState
         * variable has not been set yet.
-        * Ignore the error here since the correct FmpState variable
-        * is set later.
         */
-       efi_get_variable_int(varname, image_type_id, NULL, &size, var_state,
-                            NULL);
+       ret = efi_get_variable_int(varname, image_type_id, NULL, &size,
+                                  var_state, NULL);
+       if (ret != EFI_SUCCESS)
+               memset(var_state, 0, num_banks * sizeof(*var_state));
 
        /*
         * Only the fw_version is set here.