summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@google.com>2023-01-15 14:50:25 +1100
committerAnastasia Klimchuk <aklm@chromium.org>2023-01-22 05:56:12 +0000
commitdd41980f1784c91dd8b30a9074a260621d366c2e (patch)
treea9a006d60a296cc3a92f4826348185aeff5b30ec /tests
parent46856234b3b6dea93e38c499eecbb432cb1e455e (diff)
downloadflashrom-dd41980f1784c91dd8b30a9074a260621d366c2e.tar.gz
flashrom-dd41980f1784c91dd8b30a9074a260621d366c2e.tar.bz2
flashrom-dd41980f1784c91dd8b30a9074a260621d366c2e.zip
tests/: Assert on NULL heap allocations in tests
Change-Id: Id2adcfe859fb25d2a7f0734655c6b9a58c0890b6 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/71919 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/chip.c6
-rw-r--r--tests/chip_wp.c1
-rw-r--r--tests/helpers.c1
-rw-r--r--tests/raiden_debug_spi.c5
4 files changed, 13 insertions, 0 deletions
diff --git a/tests/chip.c b/tests/chip.c
index dc2ca11b6..ad0d7701d 100644
--- a/tests/chip.c
+++ b/tests/chip.c
@@ -279,6 +279,7 @@ void read_chip_test_success(void **state)
const char *const filename = "read_chip.test";
unsigned long size = mock_chip.total_size * 1024;
unsigned char *buf = calloc(size, sizeof(unsigned char));
+ assert_non_null(buf);
printf("Read chip operation started.\n");
assert_int_equal(0, flashrom_image_read(&flashctx, buf, size));
@@ -316,6 +317,7 @@ void read_chip_with_dummyflasher_test_success(void **state)
const char *const filename = "read_chip.test";
unsigned long size = mock_chip.total_size * 1024;
unsigned char *buf = calloc(size, sizeof(unsigned char));
+ assert_non_null(buf);
printf("Read chip operation started.\n");
assert_int_equal(0, flashrom_image_read(&flashctx, buf, size));
@@ -365,6 +367,7 @@ void write_chip_test_success(void **state)
const char *const filename = "-";
unsigned long size = mock_chip.total_size * 1024;
uint8_t *const newcontents = malloc(size);
+ assert_non_null(newcontents);
printf("Write chip operation started.\n");
assert_int_equal(0, read_buf_from_file(newcontents, size, filename));
@@ -403,6 +406,7 @@ void write_chip_with_dummyflasher_test_success(void **state)
const char *const filename = "-";
unsigned long size = mock_chip.total_size * 1024;
uint8_t *const newcontents = malloc(size);
+ assert_non_null(newcontents);
printf("Write chip operation started.\n");
assert_int_equal(0, read_buf_from_file(newcontents, size, filename));
@@ -542,6 +546,7 @@ void verify_chip_test_success(void **state)
const char *const filename = "-";
unsigned long size = mock_chip.total_size * 1024;
uint8_t *const newcontents = malloc(size);
+ assert_non_null(newcontents);
printf("Verify chip operation started.\n");
assert_int_equal(0, read_buf_from_file(newcontents, size, filename));
@@ -581,6 +586,7 @@ void verify_chip_with_dummyflasher_test_success(void **state)
const char *const filename = "-";
unsigned long size = mock_chip.total_size * 1024;
uint8_t *const newcontents = malloc(size);
+ assert_non_null(newcontents);
/*
* Dummyflasher controls chip state and fully emulates reads and writes,
diff --git a/tests/chip_wp.c b/tests/chip_wp.c
index f20b5001d..cb9b3ab40 100644
--- a/tests/chip_wp.c
+++ b/tests/chip_wp.c
@@ -269,6 +269,7 @@ void full_chip_erase_with_wp_dummyflasher_test_success(void **state)
* be optimized away. */
unsigned long size = flashrom_flash_getsize(&flash);
uint8_t *const contents = malloc(size);
+ assert_non_null(contents);
memset(contents, UNERASED_VALUE(&flash), size);
assert_int_equal(0, flashrom_image_write(&flash, contents, size, NULL));
free(contents);
diff --git a/tests/helpers.c b/tests/helpers.c
index e2e652edf..271fb4831 100644
--- a/tests/helpers.c
+++ b/tests/helpers.c
@@ -45,6 +45,7 @@ void strcat_realloc_test_success(void **state)
const char src0[] = "hello";
const char src1[] = " world";
char *dest = calloc(1, 1);
+ assert_non_null(dest);
dest = strcat_realloc(dest, src0);
dest = strcat_realloc(dest, src1);
assert_string_equal("hello world", dest);
diff --git a/tests/raiden_debug_spi.c b/tests/raiden_debug_spi.c
index f5bf185a2..5c79a9095 100644
--- a/tests/raiden_debug_spi.c
+++ b/tests/raiden_debug_spi.c
@@ -19,6 +19,7 @@
static ssize_t raiden_debug_libusb_get_device_list(void *state, libusb_context *ctx, libusb_device ***list)
{
*list = calloc(1, sizeof(**list));
+ assert_non_null(*list);
/*
* libusb_device is opaque type, it is tossed around between libusb functions but always
@@ -48,10 +49,14 @@ static int raiden_debug_libusb_get_config_descriptor(
void *state, libusb_device *dev, uint8_t config_index, struct libusb_config_descriptor **config)
{
*config = calloc(1, sizeof(**config));
+ assert_non_null(*config);
struct libusb_endpoint_descriptor *tmp_endpoint = calloc(2, sizeof(*tmp_endpoint));
+ assert_non_null(tmp_endpoint);
struct libusb_interface_descriptor *tmp_interface_desc = calloc(1, sizeof(*tmp_interface_desc));
+ assert_non_null(tmp_interface_desc);
struct libusb_interface *tmp_interface = calloc(1, sizeof(*tmp_interface));
+ assert_non_null(tmp_interface);
/* in endpoint */
tmp_endpoint[0].bEndpointAddress = 0x80;