diff options
| -rw-r--r-- | sbat.c | 2 | ||||
| -rw-r--r-- | test-sbat.c | 57 |
2 files changed, 58 insertions, 1 deletions
@@ -309,7 +309,7 @@ preserve_sbat_uefi_variable(UINT8 *sbat, UINTN sbatsize, UINT32 attributes) { return check_sbat_var_attributes(attributes) && sbatsize >= strlen(SBAT_VAR_SIG "1") && - strncmp((const char *)sbat, SBAT_VAR_SIG, strlen(SBAT_VAR_SIG)); + !strncmp((const char *)sbat, SBAT_VAR_SIG, strlen(SBAT_VAR_SIG)); } EFI_STATUS diff --git a/test-sbat.c b/test-sbat.c index 780e5cbe..8b94ecf0 100644 --- a/test-sbat.c +++ b/test-sbat.c @@ -953,6 +953,58 @@ test_parse_and_verify(void) } int +test_preserve_sbat_uefi_variable_good(void) +{ + char sbat[] = "sbat,1,\ncomponent,2,\n"; + size_t sbat_size = sizeof(sbat); + UINT32 attributes = SBAT_VAR_ATTRS; + + if (preserve_sbat_uefi_variable(sbat, sbat_size, attributes)) + return 0; + else + return -1; +} + +int +test_preserve_sbat_uefi_variable_bad_sig(void) +{ + char sbat[] = "bad_sig,1,\ncomponent,2,\n"; + size_t sbat_size = sizeof(sbat); + UINT32 attributes = SBAT_VAR_ATTRS; + + if (preserve_sbat_uefi_variable(sbat, sbat_size, attributes)) + return -1; + else + return 0; +} + +int +test_preserve_sbat_uefi_variable_bad_attr(void) +{ + char sbat[] = "sbat,1,\ncomponent,2,\n"; + size_t sbat_size = sizeof(sbat); + UINT32 attributes = 0; + + if (preserve_sbat_uefi_variable(sbat, sbat_size, attributes)) + return -1; + else + return 0; +} + +int +test_preserve_sbat_uefi_variable_bad_short(void) +{ + char sbat[] = "sba"; + size_t sbat_size = sizeof(sbat); + UINT32 attributes = SBAT_VAR_ATTRS; + + if (preserve_sbat_uefi_variable(sbat, sbat_size, attributes)) + return -1; + else + return 0; +} + +int main(void) { int status = 0; @@ -989,6 +1041,11 @@ main(void) #endif test(test_parse_and_verify); + test(test_preserve_sbat_uefi_variable_good); + test(test_preserve_sbat_uefi_variable_bad_sig); + test(test_preserve_sbat_uefi_variable_bad_attr); + test(test_preserve_sbat_uefi_variable_bad_short); + return 0; } |
