Unit test for security-hardening features of the infix library.
This test file verifies several critical security mechanisms designed to make the library resilient against common memory corruption vulnerabilities. Since these tests involve intentionally triggering crashes, they are executed in child processes to avoid terminating the main test runner.
The test covers:
- Use-After-Free (UAF) Prevention:
- It creates a trampoline (forward bound, forward unbound, and reverse), destroys it, and then attempts to call the dangling function pointer.
- It verifies that this action results in an immediate and controlled crash (e.g., a
SIGSEGV), proving that the "guard page" mechanism in infix_executable_free is working correctly.
- Context Memory Hardening:
- It creates a reverse trampoline, whose context struct is allocated in a special memory region.
- After creation, the JIT engine makes this memory region read-only.
- The test then attempts to write to a field within this context (
rt->user_data).
- It verifies that this write attempt causes a crash, proving that the context is successfully protected from runtime memory corruption.
- API Hardening against Integer Overflows:
- It calls
infix_type_create_* functions with maliciously crafted inputs designed to cause integer overflows during size and layout calculations (e.g., creating an array with SIZE_MAX elements).
- It verifies that the API functions detect these overflows, return an error status (
INFIX_ERROR_INVALID_ARGUMENT), and do not proceed with a potentially dangerous allocation.