From a7616d6d23f99718b009012505fbd7f58dae53cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 2 Oct 2018 12:53:39 +0300 Subject: [PATCH] Add helpful printouts in stacksmash.c --- test/stacksmash.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/stacksmash.c b/test/stacksmash.c index 27fee0f..a5b4523 100644 --- a/test/stacksmash.c +++ b/test/stacksmash.c @@ -16,13 +16,23 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include + __attribute__((noinline)) void func(char *ptr) { ptr[10] = 0; } + int main(int argc, char *argv[]) { char buf[10]; - if (argc > 1) + if (argc > 1) { + fprintf(stderr, "smashing stack\n"); + fflush(stderr); func(buf); + } else { + fprintf(stderr, "%s: A test tool for detecting stack smashing.\n" + "Run this with a command line argument to trigger an " + "error.\n", argv[0]); + } return 0; }