Improve toy example

- In release mode, fuzz_me was being inlined
- Make the buggy library more interesting in terms of control flow paths
This commit is contained in:
stong
2021-05-04 03:48:04 -04:00
parent 5b2b5a4a4f
commit 7b6a601e4d
2 changed files with 19 additions and 13 deletions
+3 -3
View File
@@ -21,15 +21,15 @@ void check_fwrite()
counter++;
}
void __stdcall fuzz_me(char* filename)
__declspec(noinline) void __stdcall fuzz_me(char* filename)
{
char buf[201];
ZeroMemory(&buf, 201);
FILE *fp = fopen(filename, "rb");
fread(buf, 1, 200, fp);
test_func_t Math_test_func = (test_func_t) GetProcAddress(hMathlib, "test"); // index
int result = Math_test_func(buf);
test_func_t test_func = (test_func_t) GetProcAddress(hMathlib, "test"); // index
int result = test_func(buf);
printf("Result: %d\n", result);
fclose(fp);
+16 -10
View File
@@ -15,28 +15,34 @@ extern "C" __declspec(dllexport) int test(char *input)
int v9;
printf("msg:%s\n", input);
if ( *input == 't' )
if ( input[0] != 't' )
{
printf("Error 1\n");
return 0;
}
if ( input[1] == 'e' )
if ( input[1] != 'e' )
{
printf("Error 2\n");
return 0;
}
if ( input[2] == 's' )
if ( input[2] != 's' )
{
printf("Error 3\n");
return 0;
}
if (input[3] == '*' )
{
// simple nullptr deref
*(volatile char*)0 = 1;
return 0;
}
else if (input[3] == '!')
{
// trigger a timeout
Sleep(5000);
return 0;
}
v2 = input[3];
if ( v2 == 't' )
{
*(char*)0 = 1;
return 0;
}
if ( v2 != 101 )
else if (input[3] != 't' )
{
printf("Error 4\n");
return 0;