diff --git a/README.adoc b/README.adoc index bbbc17d..d4e1be6 100644 --- a/README.adoc +++ b/README.adoc @@ -13096,6 +13096,16 @@ The following sections are related to multithreading in userland: ** <> ** <> +=== 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 diff --git a/path_properties.py b/path_properties.py index 802e486..4dec6bc 100644 --- a/path_properties.py +++ b/path_properties.py @@ -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}, diff --git a/userland/c/smash_stack.c b/userland/c/smash_stack.c new file mode 100644 index 0000000..61aa080 --- /dev/null +++ b/userland/c/smash_stack.c @@ -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; +}