stack smashing

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-09-07 00:00:00 +00:00
parent 2e4b360512
commit a1cf89efba
3 changed files with 30 additions and 0 deletions

17
userland/c/smash_stack.c Normal file
View File

@@ -0,0 +1,17 @@
/* https://cirosantilli.com/linux-kernel-module-cheat#stack-smashing */
void myfunc(char *const src, int len) {
int i;
for (i = 0; i < len; ++i) {
src[i] = 42;
}
}
int main(void) {
char arr[] = {'a', 'b', 'c', 'd'};
int len = sizeof(arr);
myfunc(arr, len);
myfunc(arr, len + 1);
myfunc(arr, len);
return 0;
}