Skip to content

Commit 89a1c57

Browse files
tniessendanielleadams
authored andcommitted
test: use CHECK instead of EXPECT where necessary
GetPageSize() and OverrunGuardedBuffer currently use non-fatal EXPECT_* macros because GoogleTest does not allow the fatal variants ASSERT_* in non-void returning functions (i.e., in this file, nowhere outside of the TEST itself). The EXPECT_* macros continue execution upon failure, but we really don't want that (and static analysis apparently does not like it either). Since we cannot use GoogleTest's ASSERT_* here, use our own CHECK_* instead of EXPECT_* outside of the TEST. Hopefully, this will finally pacify static analysis. Refs: #44666 PR-URL: #44795 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Erick Wendel <erick.workspace@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent 4494cb2 commit 89a1c57

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

test/cctest/test_crypto_clienthello.cc

+9-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#if defined(USE_MPROTECT)
3333
size_t GetPageSize() {
3434
int page_size = sysconf(_SC_PAGE_SIZE);
35-
EXPECT_GE(page_size, 1);
35+
CHECK_GE(page_size, 1);
3636
return page_size;
3737
}
3838
#elif defined(USE_VIRTUALPROTECT)
@@ -49,32 +49,32 @@ class OverrunGuardedBuffer {
4949
OverrunGuardedBuffer() {
5050
#if defined(USE_MPROTECT) || defined(USE_VIRTUALPROTECT)
5151
size_t page = GetPageSize();
52-
EXPECT_GE(page, N);
52+
CHECK_GE(page, N);
5353
#endif
5454
#ifdef USE_MPROTECT
5555
// Place the packet right before a guard page, which, when accessed, causes
5656
// a segmentation fault.
5757
alloc_base = static_cast<uint8_t*>(aligned_alloc(page, 2 * page));
58-
EXPECT_NE(alloc_base, nullptr);
58+
CHECK_NOT_NULL(alloc_base);
5959
uint8_t* second_page = alloc_base + page;
60-
EXPECT_EQ(mprotect(second_page, page, PROT_NONE), 0);
60+
CHECK_EQ(mprotect(second_page, page, PROT_NONE), 0);
6161
data_base = second_page - N;
6262
#elif defined(USE_VIRTUALPROTECT)
6363
// On Windows, it works almost the same way.
6464
alloc_base = static_cast<uint8_t*>(
6565
VirtualAlloc(nullptr, 2 * page, MEM_COMMIT, PAGE_READWRITE));
66-
EXPECT_NE(alloc_base, nullptr);
66+
CHECK_NOT_NULL(alloc_base);
6767
uint8_t* second_page = alloc_base + page;
6868
DWORD old_prot;
69-
EXPECT_NE(VirtualProtect(second_page, page, PAGE_NOACCESS, &old_prot), 0);
70-
EXPECT_EQ(old_prot, PAGE_READWRITE);
69+
CHECK_NE(VirtualProtect(second_page, page, PAGE_NOACCESS, &old_prot), 0);
70+
CHECK_EQ(old_prot, PAGE_READWRITE);
7171
data_base = second_page - N;
7272
#else
7373
// Place the packet in a regular allocated buffer. The bug causes undefined
7474
// behavior, which might crash the process, and when it does not, address
7575
// sanitizers and valgrind will catch it.
7676
alloc_base = static_cast<uint8_t*>(malloc(N));
77-
EXPECT_NE(alloc_base, nullptr);
77+
CHECK_NOT_NULL(alloc_base);
7878
data_base = alloc_base;
7979
#endif
8080
}
@@ -92,7 +92,7 @@ class OverrunGuardedBuffer {
9292
#ifdef USE_MPROTECT
9393
// Revert page protection such that the memory can be free()'d.
9494
uint8_t* second_page = alloc_base + page;
95-
EXPECT_EQ(mprotect(second_page, page, PROT_READ | PROT_WRITE), 0);
95+
CHECK_EQ(mprotect(second_page, page, PROT_READ | PROT_WRITE), 0);
9696
#endif
9797
free(alloc_base);
9898
#endif

0 commit comments

Comments
 (0)