Skip to content
Snippets Groups Projects
ContextOutOfBoundsTest.cpp 960 B
Newer Older
  • Learn to ignore specific revisions
  • // SPDX-License-Identifier: LGPL-3.0-or-later
    // Copyright © 2022 Florian Fischer
    
    static auto recur(uintptr_t depth, int val) -> int {
    	if (depth == UINTPTR_MAX) return val;
    
    	constexpr size_t stack_user_size = 1024;
    	std::array<int, stack_user_size> stack_user;
    	for (int& i : stack_user) {
    		// NOLINTNEXTLINE(cert-msc32-c,cert-msc51-cpp)
    		i = rand();
    
    	int res = recur(depth + 1, stack_user[stack_user_size - 1]);
    
    	for (int i : stack_user) {
    		res += i;
    
    	return res;
    }
    
    void emperTest() {
    	// This test should exit(EXIT_SUCCESS) if EMPER successfully
    	// detected a stack guard-page hit.
    	Runtime::setGuardPageTouchCausesExitSuccess();
    
    	int res = recur(0, 0);
    
    	// This should never return a result.
    	std::cerr << "ERROR: Got result: " << res;
    
    	// This should never be reached, instead the guard page should have been hit.
    	exit(EXIT_FAILURE);