-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a test case for our address sanitation checking function ImageAddresS(). In doing so it addresses two issues: - previously we allowed the address after the last byte of the image to be computed (may need to revert this or fix some callers, we'll see...) - bespoke overflow checking and using + directly instead of using __builtin_add_overflow() Signed-off-by: Peter Jones <pjones@redhat.com>
- Loading branch information
Showing
7 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!/*.efi |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause-Patent | ||
/* | ||
* test-pe-reloc.c - attempt to test relocate_coff() | ||
* Copyright Peter Jones <pjones@redhat.com> | ||
*/ | ||
|
||
#ifndef SHIM_UNIT_TEST | ||
#define SHIM_UNIT_TEST | ||
#endif | ||
#include "shim.h" | ||
|
||
static int | ||
test_image_address(void) | ||
{ | ||
char image[4]; | ||
void *ret; | ||
|
||
assert_equal_return(ImageAddress(image, sizeof(image), 0), &image[0], -1, "got %p expected %p\n"); | ||
assert_equal_return(ImageAddress(image, sizeof(image), 4), NULL, -1, "got %p expected %p\n"); | ||
assert_equal_return(ImageAddress((void *)1, 2, 3), NULL, -1, "got %p expected %p\n"); | ||
assert_equal_return(ImageAddress((void *)-1ull, UINT64_MAX, UINT64_MAX), NULL, -1, "got %p expected %p\n"); | ||
assert_equal_return(ImageAddress((void *)0, UINT64_MAX, UINT64_MAX), NULL, -1, "got %p expected %p\n"); | ||
assert_equal_return(ImageAddress((void *)1, UINT64_MAX, UINT64_MAX), NULL, -1, "got %p expected %p\n"); | ||
assert_equal_return(ImageAddress((void *)2, UINT64_MAX, UINT64_MAX), NULL, -1, "got %p expected %p\n"); | ||
assert_equal_return(ImageAddress((void *)3, UINT64_MAX, UINT64_MAX), NULL, -1, "got %p expected %p\n"); | ||
|
||
return 0; | ||
} | ||
|
||
int | ||
main(void) | ||
{ | ||
int status = 0; | ||
test(test_image_address); | ||
|
||
return status; | ||
} | ||
|
||
// vim:fenc=utf-8:tw=75:noet |