Skip to content

Commit

Permalink
i386/slaunch: improve error recovery of "slaunch_module" command
Browse files Browse the repository at this point in the history
Update `slaunch_module` global only if new module passed all checks.

Closes #11.

Signed-off-by: Sergii Dmytruk <[email protected]>
  • Loading branch information
SergiiDmytruk committed Feb 27, 2024
1 parent d5f9d08 commit 13bf69f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions grub-core/loader/i386/slaunch.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ grub_cmd_slaunch_module (grub_command_t cmd __attribute__ ((unused)),
{
grub_file_t file;
grub_ssize_t size;
void *new_module = NULL;

if (!argc)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
Expand All @@ -231,12 +232,12 @@ grub_cmd_slaunch_module (grub_command_t cmd __attribute__ ((unused)),
goto fail;
}

slaunch_module = grub_malloc (size);
new_module = grub_malloc (size);

if (slaunch_module == NULL)
if (new_module == NULL)
goto fail;

if (grub_file_read (file, slaunch_module, size) != size)
if (grub_file_read (file, new_module, size) != size)
{
if (grub_errno == GRUB_ERR_NONE)
grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file: %s"),
Expand All @@ -246,21 +247,21 @@ grub_cmd_slaunch_module (grub_command_t cmd __attribute__ ((unused)),

if (slp == SLP_INTEL_TXT)
{
if (!grub_txt_is_sinit_acmod (slaunch_module, size))
if (!grub_txt_is_sinit_acmod (new_module, size))
{
grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("it does not look like SINIT ACM"));
goto fail;
}

if (!grub_txt_acmod_match_platform (slaunch_module))
if (!grub_txt_acmod_match_platform (new_module))
{
grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("SINIT ACM does not match platform"));
goto fail;
}
}
else if (slp == SLP_AMD_SKINIT)
{
if (!grub_skinit_is_slb (slaunch_module, size))
if (!grub_skinit_is_slb (new_module, size))
{
grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("it does not look like SLB"));
goto fail;
Expand All @@ -269,16 +270,17 @@ grub_cmd_slaunch_module (grub_command_t cmd __attribute__ ((unused)),

grub_file_close (file);

grub_free (slaunch_module);
slaunch_module = new_module;

return GRUB_ERR_NONE;

fail:
grub_error_push ();

grub_free (slaunch_module);
grub_free (new_module);
grub_file_close (file);

slaunch_module = NULL;

grub_error_pop ();

return grub_errno;
Expand Down

0 comments on commit 13bf69f

Please sign in to comment.