mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
stack smashing
This commit is contained in:
10
README.adoc
10
README.adoc
@@ -13096,6 +13096,16 @@ The following sections are related to multithreading in userland:
|
||||
** <<number-of-cores-in-qemu-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
|
||||
|
||||
* 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
|
||||
|
||||
@@ -480,6 +480,9 @@ path_properties_tuples = (
|
||||
'assert_fail.c': {
|
||||
'signal_received': signal.Signals.SIGABRT,
|
||||
},
|
||||
'smash_stack.c': {
|
||||
'skip_run_unclassified': True,
|
||||
},
|
||||
'exit1.c': {'exit_status': 1},
|
||||
'exit2.c': {'exit_status': 2},
|
||||
'false.c': {'exit_status': 1},
|
||||
|
||||
17
userland/c/smash_stack.c
Normal file
17
userland/c/smash_stack.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user