From: Martin Willi Date: Wed, 8 Apr 2015 08:16:13 +0000 (+0200) Subject: unit-tests: Exclude memory checks after-free from AddressSanitizer X-Git-Tag: 5.9.8dr4~11^2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7dce58135e1a8b8bde224c7da2fdcce7e4c83c17;p=thirdparty%2Fstrongswan.git unit-tests: Exclude memory checks after-free from AddressSanitizer We explicitly test the memory we free()d if that got properly wiped, so suppress the warning from AddressSanitizer. --- diff --git a/src/libstrongswan/tests/suites/test_chunk.c b/src/libstrongswan/tests/suites/test_chunk.c index 3f72381526..93753c7398 100644 --- a/src/libstrongswan/tests/suites/test_chunk.c +++ b/src/libstrongswan/tests/suites/test_chunk.c @@ -125,12 +125,27 @@ END_TEST * clear */ +ADDRESS_SANITIZER_EXCLUDE +static bool cleared(u_char *ptr) +{ + int i; + + for (i = 0; i < 64; i += 2) + { + if (ptr[i] != 0 && ptr[i] == i && + ptr[i+1] != 0 && ptr[i+1] == i+1) + { + return FALSE; + } + } + return TRUE; +} + START_TEST(test_chunk_clear) { chunk_t chunk; u_char *ptr; int i; - bool cleared = TRUE; chunk = chunk_empty; chunk_clear(&chunk); @@ -147,17 +162,8 @@ START_TEST(test_chunk_clear) * test directly, as it might allocate data at the freed area. comparing * two bytes at once reduces the chances of conflicts if memory got * overwritten already */ - for (i = 0; i < 64; i += 2) - { - if (ptr[i] != 0 && ptr[i] == i && - ptr[i+1] != 0 && ptr[i+1] == i+1) - { - cleared = FALSE; - break; - } - } + ck_assert(cleared(ptr)); assert_chunk_empty(chunk); - ck_assert(cleared); } END_TEST @@ -199,6 +205,27 @@ END_TEST * chunk_create_cat */ +ADDRESS_SANITIZER_EXCLUDE +bool chunk_equals_nosan(chunk_t a, chunk_t b) +{ + int i; + + /* cant use memcmp() or any function using it, as that is again + * sanitize-checked */ + if (a.len != b.len) + { + return FALSE; + } + for (i = 0; i < b.len; i++) + { + if (a.ptr[i] != b.ptr[i]) + { + return FALSE; + } + } + return TRUE; +} + START_TEST(test_chunk_create_cat) { chunk_t foo, bar; @@ -236,8 +263,8 @@ START_TEST(test_chunk_create_cat) ck_assert_int_eq(c.len, 6); ck_assert(chunk_equals(c, chunk_from_str("foobar"))); /* check memory area of cleared chunk */ - ck_assert(!chunk_equals(foo, chunk_create(ptra, 3))); - ck_assert(!chunk_equals(bar, chunk_create(ptrb, 3))); + ck_assert(!chunk_equals_nosan(foo, chunk_create(ptra, 3))); + ck_assert(!chunk_equals_nosan(bar, chunk_create(ptrb, 3))); } END_TEST