Skip to content
Permalink
Browse files

Fix unsigned long tainted_volatile test to run only on platforms wher…

…e unsigned long differs in size from the sandbox
  • Loading branch information
shravanrn committed Jan 18, 2020
1 parent ea71a69 commit 4705d7e34ee971ef2aac55b3875e48fc0f8aeca2
Showing with 17 additions and 12 deletions.
  1. +17 −12 code/tests/rlbox/test_tainted_assignment.cpp
@@ -36,18 +36,23 @@ TEST_CASE("tainted_volatile assignment operates correctly",
rlbox::rlbox_sandbox<TestSandbox> sandbox;
sandbox.create_sandbox();

// uint64_t on 64 bit platforms is "unsigned long" which is 64 bits in the app
// but long is 32-bits in our test sandbox env
auto pc = sandbox.malloc_in_sandbox<uint64_t>();

uint64_t max32Val = std::numeric_limits<uint32_t>::max();
*pc = max32Val;

REQUIRE((*pc).UNSAFE_unverified() == max32Val);
REQUIRE(pc->UNSAFE_unverified() == max32Val);

uint64_t max64Val = std::numeric_limits<uint64_t>::max();
REQUIRE_THROWS(*pc = max64Val);
// On 64 bit platforms, "unsigned long" is 64 bits in the app
// but unsigned long is 32-bits in our test sandbox env
// NOLINTNEXTLINE(google-runtime-int)
auto pc = sandbox.malloc_in_sandbox<unsigned long>();

// Only run this test for platforms where unsigned long is 64 bits
// NOLINTNEXTLINE(google-runtime-int)
if constexpr (sizeof(unsigned long) == sizeof(uint64_t)) {
uint64_t max32Val = std::numeric_limits<uint32_t>::max();
*pc = max32Val;

REQUIRE((*pc).UNSAFE_unverified() == max32Val);
REQUIRE(pc->UNSAFE_unverified() == max32Val);

uint64_t max64Val = std::numeric_limits<uint64_t>::max();
REQUIRE_THROWS(*pc = max64Val);
}

sandbox.destroy_sandbox();
}

0 comments on commit 4705d7e

Please sign in to comment.
You can’t perform that action at this time.