-
-
Save murx-/5c490c14f4ea994dd7e8bf6d49fdb3b2 to your computer and use it in GitHub Desktop.
Example of a vulnerable program for a blogpost.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#include <stdio.h> | |
void vuln() { | |
int* n = (void*) 0; | |
*n = 42; | |
} | |
int main() { | |
char buf[100]; | |
int len = read(0, &buf, 99); | |
buf[len] = '\x00'; | |
printf("%s\n", buf); | |
if (buf[0] == '0') | |
vuln(); | |
if (buf[0] == '1') | |
vuln(); | |
if (buf[0] == '2') | |
vuln(); | |
if (buf[0] == '3') | |
vuln(); | |
if (buf[0] == '4') | |
vuln(); | |
if (buf[0] == '5') | |
vuln(); | |
if (buf[0] == '6') | |
vuln(); | |
if (buf[0] == '7') | |
vuln(); | |
if (buf[0] == '8') | |
vuln(); | |
if (buf[0] == '9') | |
vuln(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment