Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sbat_var.S parse right with buggy gcc/binutils #535

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ test-mock-variables: CFLAGS+=-DHAVE_SHIM_LOCK_GUID
test-mok-mirror_FILES = mok.c globals.c tpm.c lib/guid.c lib/variables.c mock-variables.c
test-mok-mirror: CFLAGS+=-DHAVE_START_IMAGE -DHAVE_SHIM_LOCK_GUID

test-sbat_FILES = csv.c lib/variables.c lib/guid.c sbat_var.S
test-sbat_FILES = csv.c lib/variables.c lib/guid.c sbat_var.S mock-variables.c
test-sbat :: CFLAGS+=-DHAVE_GET_VARIABLE -DHAVE_GET_VARIABLE_ATTR -DHAVE_SHIM_LOCK_GUID

test-str_FILES = lib/string.c
Expand Down
6 changes: 4 additions & 2 deletions sbat_var.S
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ sbat_var_payload_header:
.Lsbat_var_payload_header_end:
.balign 1, 0
.Lsbat_var_previous:
.asciz SBAT_VAR_PREVIOUS
.ascii SBAT_VAR_PREVIOUS
.byte 0
.balign 1, 0
.Lsbat_var_latest:
.asciz SBAT_VAR_LATEST
.ascii SBAT_VAR_LATEST
.byte 0
32 changes: 32 additions & 0 deletions test-sbat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,36 @@ test_preserve_sbat_uefi_variable_bad_short(void)
return 0;
}

static int
test_sbat_var_asciz(void)
{
EFI_STATUS status;
char buf[1024] = "";
UINT32 attrs = 0;
UINTN size = sizeof(buf);
char expected[] = SBAT_VAR_PREVIOUS;

status = set_sbat_uefi_variable();
if (status != EFI_SUCCESS)
return -1;

status = RT->GetVariable(SBAT_VAR_NAME, &SHIM_LOCK_GUID, &attrs, &size, buf);
if (status != EFI_SUCCESS)
return -1;

/*
* this should be enough to get past "sbat,", which handles the
* first error.
*/
if (size < (strlen(SBAT_VAR_SIG) + 2) || size != strlen(expected))
return -1;

if (strncmp(expected, buf, size) != 0)
return -1;

return 0;
}

int
main(void)
{
Expand Down Expand Up @@ -1155,6 +1185,8 @@ main(void)
test(test_preserve_sbat_uefi_variable_version_older);
test(test_preserve_sbat_uefi_variable_version_olderlonger);

test(test_sbat_var_asciz);

return 0;
}

Expand Down