From: Azat Khuzhin Date: Sun, 12 Feb 2023 16:05:20 +0000 (+0100) Subject: test: enable allocator_may_return_null=1 for calloc with ENOMEM test X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1df2a5a69efc7f9653c8867f81259ade957ad030;p=libevent test: enable allocator_may_return_null=1 for calloc with ENOMEM test --- diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ad3a4d2b..66201571 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -134,8 +134,10 @@ jobs: export CTEST_PARALLEL_LEVEL=$JOBS export CTEST_OUTPUT_ON_FAILURE=1 - export TSAN_OPTIONS=suppressions=$PWD/extra/tsan.supp + # Enable allocator_may_return_null for test_event_calloc_enomem + export TSAN_OPTIONS=suppressions=$PWD/extra/tsan.supp:allocator_may_return_null=1 export LSAN_OPTIONS=suppressions=$PWD/extra/lsan.supp + export ASAN_OPTIONS=allocator_may_return_null=1 if [ "${{ matrix.EVENT_MATRIX }}" == "DIST" ]; then cd dist diff --git a/test/regress_util.c b/test/regress_util.c index 63222516..430b3cdd 100644 --- a/test/regress_util.c +++ b/test/regress_util.c @@ -1310,6 +1310,17 @@ test_event_calloc(void *arg) mm_free(p); p = NULL; + end: + errno = 0; + if (p) + mm_free(p); +} + +static void +test_event_calloc_enomem(void *arg) +{ + void *p = NULL; + /* mm_calloc() should set errno = ENOMEM and return NULL * in case of potential overflow. */ errno = 0; @@ -1318,6 +1329,7 @@ test_event_calloc(void *arg) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Walloc-size-larger-than=" #endif + /* Requires allocator_may_return_null=1 for sanitizers */ p = mm_calloc(EV_SIZE_MAX, EV_SIZE_MAX); #if defined(__clang__) #elif defined(__GNUC__) @@ -1327,11 +1339,7 @@ test_event_calloc(void *arg) tt_int_op(errno, ==, ENOMEM); end: - errno = 0; - if (p) - mm_free(p); - - return; + ; } static void @@ -1857,6 +1865,7 @@ struct testcase_t util_testcases[] = { #endif { "mm_malloc", test_event_malloc, 0, NULL, NULL }, { "mm_calloc", test_event_calloc, 0, NULL, NULL }, + { "mm_calloc_enomem", test_event_calloc_enomem, 0, NULL, NULL }, { "mm_strdup", test_event_strdup, 0, NULL, NULL }, { "usleep", test_evutil_usleep, TT_RETRIABLE, NULL, NULL }, { "monotonic_res", test_evutil_monotonic_res, 0, &basic_setup, (void*)"" },