summaryrefslogtreecommitdiff
path: root/overflow.c
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2012-09-26 15:04:18 +0200
committerPeter Wu <lekensteyn@gmail.com>2012-09-26 15:04:18 +0200
commit2497c1392b81e093f4de2541a98746aebd449a7f (patch)
treedb87e59d4c70c677ddb1899d9161b004f6e454ac /overflow.c
downloadc-files-2497c1392b81e093f4de2541a98746aebd449a7f.tar.gz
Initial commit
Diffstat (limited to 'overflow.c')
-rw-r--r--overflow.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/overflow.c b/overflow.c
new file mode 100644
index 0000000..1a01984
--- /dev/null
+++ b/overflow.c
@@ -0,0 +1,31 @@
+/**
+ * 27-08-2012 buffer overflow exercise
+ * gcc -fstack-protector-all -D_FORTIFY_SOURCE=2 -O2 -Wall -g overflow.c -o overflow
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+void g() {
+ static int j = 0;
+ printf("Call %u\n", ++j);
+}
+void bye() {
+ puts("Last call - ciao");
+ exit(42);
+}
+
+void f() {
+ unsigned int i;
+ void * x[0];
+ scanf("%u", &i);
+ puts("From f()");
+ x[++i] = bye;
+ while (i--)
+ x[i] = g;
+ printf("Stuff: %p\n", x);
+}
+
+int main() {
+ f();
+ return 0;
+}