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

View File

@@ -13096,6 +13096,16 @@ The following sections are related to multithreading in userland:
** <<number-of-cores-in-qemu-user-mode>> ** <<number-of-cores-in-qemu-user-mode>>
** <<number-of-cores-in-gem5-user-mode>> ** <<number-of-cores-in-gem5-user-mode>>
=== C debugging
Let's group the hard-to-debug undefined-behaviour-like stuff found in C / C+ here and how to tackle those problems.
==== Stack smashing
https://stackoverflow.com/questions/1345670/stack-smashing-detected/51897264#51897264
link:userland/c/smash_stack.c[]
=== Userland content bibliography === Userland content bibliography
* The Linux Programming Interface by Michael Kerrisk https://www.amazon.co.uk/Linux-Programming-Interface-System-Handbook/dp/1593272200 Lots of open source POSIX examples: https://github.com/cirosantilli/linux-programming-interface-kerrisk * The Linux Programming Interface by Michael Kerrisk https://www.amazon.co.uk/Linux-Programming-Interface-System-Handbook/dp/1593272200 Lots of open source POSIX examples: https://github.com/cirosantilli/linux-programming-interface-kerrisk

View File

@@ -480,6 +480,9 @@ path_properties_tuples = (
'assert_fail.c': { 'assert_fail.c': {
'signal_received': signal.Signals.SIGABRT, 'signal_received': signal.Signals.SIGABRT,
}, },
'smash_stack.c': {
'skip_run_unclassified': True,
},
'exit1.c': {'exit_status': 1}, 'exit1.c': {'exit_status': 1},
'exit2.c': {'exit_status': 2}, 'exit2.c': {'exit_status': 2},
'false.c': {'exit_status': 1}, 'false.c': {'exit_status': 1},

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;
}