stack_protector_DeathTest: work w/ local reorder
Before, the helper method for this test had two local variables: char buf[128]; volatile char* p; Then the test wrote zeros into the buffer and one past the buffer end. This relied on the fact that the compiler constructed the stack frame with 'p' first and then the buffer (and also optimized away the 'size' variable). However, some compiler options (namely -ftrivial-auto-var-init=pattern) result in the stack frame being reordered so that 'p' is actually after buf, and the test cannot pass. Fixes: 132780819 Test: bionic-unit-tests-static (w/ w/o flag) Change-Id: Icc87c02add211c2afb7c96ae22701ec27990364c
This commit is contained in:
parent
7909f4c667
commit
06f39d36a4
|
@ -16,11 +16,10 @@
|
|||
|
||||
// Deliberately overwrite the stack canary.
|
||||
__attribute__((noinline)) void modify_stack_protector_test() {
|
||||
char buf[128];
|
||||
// We can't use memset here because it's fortified, and we want to test
|
||||
// the line of defense *after* that.
|
||||
// Without volatile, the generic x86/x86-64 targets don't write to the stack.
|
||||
volatile char* p = buf;
|
||||
int size = static_cast<int>(sizeof(buf) + sizeof(void*));
|
||||
while ((p - buf) < size) *p++ = '\0';
|
||||
volatile char* p;
|
||||
p = reinterpret_cast<volatile char*>(&p + 1);
|
||||
*p = '\0';
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue