mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-14 10:22:17 +00:00
Correctly delete UEFI variables
UEFI runtime service GetVariable with DataSize NULL, will fail and get EFI_INVALID_PARAMETER returned. Set DataSize 0 and allocate the buffer for getting attributes for the deleted variable. Also, fix the real reason Boot#### was never found.
This commit is contained in:
parent
2a026147ce
commit
44f55e2ee6
@ -17,16 +17,27 @@ fwup_delete_variable(CHAR16 *name, EFI_GUID *guid)
|
|||||||
{
|
{
|
||||||
EFI_STATUS rc;
|
EFI_STATUS rc;
|
||||||
UINT32 attrs = 0;
|
UINT32 attrs = 0;
|
||||||
|
UINTN size = 0;
|
||||||
|
|
||||||
/* get the attrs so we can delete it */
|
/* get the attrs so we can delete it */
|
||||||
rc = uefi_call_wrapper(RT->GetVariable, 5, name, guid, &attrs, NULL, NULL);
|
rc = uefi_call_wrapper(RT->GetVariable, 5, name, guid, &attrs, &size, NULL);
|
||||||
if (EFI_ERROR(rc)) {
|
if (EFI_ERROR(rc)) {
|
||||||
if (rc == EFI_NOT_FOUND) {
|
if (rc == EFI_BUFFER_TOO_SMALL) {
|
||||||
|
_cleanup_free VOID *buf = fwup_malloc(size);
|
||||||
|
if (buf == NULL)
|
||||||
|
return EFI_OUT_OF_RESOURCES;
|
||||||
|
rc = uefi_call_wrapper(RT->GetVariable, 5, name, guid, &attrs, &size, buf);
|
||||||
|
if (EFI_ERROR(rc)) {
|
||||||
|
fwup_debug(L"Could not get attr: %r", rc);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
} else if (rc == EFI_NOT_FOUND) {
|
||||||
fwup_debug(L"Not deleting variable '%s' as not found", name);
|
fwup_debug(L"Not deleting variable '%s' as not found", name);
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
|
} else {
|
||||||
|
fwup_debug(L"Could not get variable '%s' for delete: %r", name, rc);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
fwup_debug(L"Could not get variable '%s' for delete: %r", name, rc);
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
return uefi_call_wrapper(RT->SetVariable, 5, name, guid, attrs, 0, NULL);
|
return uefi_call_wrapper(RT->SetVariable, 5, name, guid, attrs, 0, NULL);
|
||||||
}
|
}
|
||||||
|
@ -408,7 +408,9 @@ fwup_delete_boot_entry(VOID)
|
|||||||
/* check if the variable name is Boot#### */
|
/* check if the variable name is Boot#### */
|
||||||
if (CompareGuid(&vendor_guid, &global_variable_guid) != 0)
|
if (CompareGuid(&vendor_guid, &global_variable_guid) != 0)
|
||||||
continue;
|
continue;
|
||||||
if (StrCmp(variable_name, L"Boot") != 0)
|
if (StrLen(variable_name) != 8)
|
||||||
|
continue;
|
||||||
|
if (StrnCmp(variable_name, L"Boot", 4) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
UINTN info_size = 0;
|
UINTN info_size = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user