Skip to content

Commit

Permalink
Add a test for detagging when setbounds attempts to reduce base
Browse files Browse the repository at this point in the history
  • Loading branch information
arichardson committed Jul 21, 2023
1 parent bf2c0a0 commit 42f7343
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/setbounds_test_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,22 @@ TEST_CASE("Setbounds length overflow", "[fuzz]") {
CHECK(result.base() < _CC_MAX_ADDR);
CHECK(result.top() == 0);
}

TEST_CASE("Setbounds base reduction", "[fuzz]") {
// Calling setbounds that reduces the base should detag and not assert
TestAPICC::cap_t cap = TestAPICC::make_max_perms_cap(/*base=*/8, /*cursor=*/2, /*top=*/11);
TestAPICC::addr_t req_len = 1;
#ifndef NDEBUG
// Overflowing cursor+base should be rejected.
CHECK_THROWS_MATCHES(_cc_N(checked_setbounds)(&cap, req_len), std::invalid_argument,
Message("cannot decrease base on tagged capabilities"));
#endif
// The result should be detagged since we are setting bounds to start at less than base top.
bool was_exact;
TestAPICC::cap_t result = do_csetbounds<TestAPICC>(cap, &was_exact, req_len);
CHECK(!result.cr_tag);
CHECK(was_exact);
CHECK(result.base() == 2);
CHECK(result.address() == 2);
CHECK(result.top() == result.base() + req_len);
}

0 comments on commit 42f7343

Please sign in to comment.