Skip to content

Commit a373122

Browse files
committed
code/C/format-string.c: Format string vulnerabilities example code
Signed-off-by: Marian Marinov <[email protected]>
1 parent 783c46a commit a373122

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

code/C/format-string.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include <stdlib.h>
4+
5+
int main (int argc, char **argv) {
6+
char buf[10] = { '\0' };
7+
int x = 1;
8+
snprintf(buf, sizeof(buf), argv[1]);
9+
buf[sizeof(buf)-1] = 0;
10+
printf("Buffer size is: (%d) \nData input: %s \n", strlen(buf), buf);
11+
printf("in hex: %#x\nMemory address for x: (%p) \n", x, &x);
12+
strdup(argv[1]);
13+
return 0;
14+
}

0 commit comments

Comments
 (0)