We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 117b58b commit 07e9e2eCopy full SHA for 07e9e2e
fork_canary
16.7 KB
fork_canary.c
@@ -0,0 +1,38 @@
1
+#include <stdio.h>
2
+#include <stdlib.h>
3
+#include <unistd.h>
4
+
5
+// gcc fork_canary.c -o ./fork_canary
6
+int main(int argc, char **argv) {
7
+ size_t index;
8
+ size_t *i = &index;
9
+ int canary_offset = 0xd;
10
11
+ // fork()
12
+ pid_t pid = fork();
13
+ if (pid == -1) {
14
+ perror("fork");
15
+ exit(EXIT_FAILURE);
16
+ }
17
18
+ // if child
19
+ if (pid == 0) {
20
+ printf("child canary?");
21
+ scanf("%p", &index);
22
23
+ if (index == i[canary_offset])
24
+ puts("canary!");
25
+ else
26
+ puts("not canary!");
27
28
+ } else {
29
+ // if parent
30
+ printf("parent canary: %p\n", i[canary_offset]);
31
+ // wait for child
32
+ int status;
33
+ waitpid(pid, &status, 0);
34
35
36
+ char *buf[10];
37
+ gets(buf);
38
+}
0 commit comments