Fix stack-protector.rs on LLVM 17

Prevent fill from being (correctly) optimized away by passing the
address of the alloca to black_box.
This commit is contained in:
Nikita Popov 2023-07-25 11:52:44 +02:00 committed by Nikita Popov
parent ad7ea8b7e6
commit 01cdc505d9

View File

@ -40,6 +40,8 @@ fn vulnerable_function() {
// Overwrite the on-stack return address with the address of `malicious_code()`, // Overwrite the on-stack return address with the address of `malicious_code()`,
// thereby jumping to that function when returning from `vulnerable_function()`. // thereby jumping to that function when returning from `vulnerable_function()`.
unsafe { fill(stackaddr, bad_code_ptr, 20); } unsafe { fill(stackaddr, bad_code_ptr, 20); }
// Capture the address, so the write is not optimized away.
std::hint::black_box(stackaddr);
} }
// Use an uninlined function with its own stack frame to make sure that we don't // Use an uninlined function with its own stack frame to make sure that we don't