SPRAD28 October 2022 AM2431 , AM2432 , AM2434 , AM2631 , AM2631-Q1 , AM2632 , AM2632-Q1 , AM2634 , AM2634-Q1 , AM263P4 , AM263P4-Q1 , AM26C31 , AM26C31-EP , AM26C31M , AM26C32 , AM26C32-EP , AM26C32C , AM26C32M , AM26LS31 , AM26LS31M , AM26LS32A , AM26LS32AC , AM26LS32AM , AM26LS33A , AM26LS33A-SP , AM26LS33AM , AM26LV31 , AM26LV31E , AM26LV31E-EP , AM26LV32 , AM26LV32E , AM26LV32E-EP , AM26S10 , AM2732 , AM2732-Q1
Here is a simple example to summarize and demonstrate how the stack smashing detection capability can be used. The first source file presents the definitions of __stack_chk_fail() and __stack_chk_guard (stack_check.c):
#include <stdlib.h>
#include <stdio.h>
void __stack_chk_fail(void);
unsigned long __stack_chk_guard = 0xbadeebad;
void __stack_chk_fail(void)
{
printf("ERROR: __stack_chk_guard has been corrupted\n");
exit(0);
}
The second source file presents a use case where a function, foo, writes past the end of a local buffer (stack_smash.c):
#include <string.h>
void foo(void);
int main() {
foo();
return 0;}void foo(void)
{
char buffer[3];
strcpy(buffer, "Oi! I am smashing your stack");
}