forked from irungentoo/toxcore
-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
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
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
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <malloc.h> | ||
#include <stdio.h> | ||
|
||
#include "../toxcore/tox.h" | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
if (argc != 2) { | ||
return -1; | ||
} | ||
|
||
// determine file size | ||
FILE *fileptr = fopen(argv[1], "rb"); | ||
fseek(fileptr, 0, SEEK_END); | ||
long filelen = ftell(fileptr); | ||
rewind(fileptr); | ||
|
||
// read file into buffer | ||
uint8_t *buffer = (uint8_t *)malloc(filelen * sizeof(uint8_t)); | ||
size_t bytes_read = fread(buffer, filelen, 1, fileptr); | ||
|
||
if (bytes_read != filelen) { | ||
free(buffer); | ||
return -1; | ||
} | ||
|
||
fclose(fileptr); | ||
|
||
TOX_ERR_OPTIONS_NEW error_options = 0; | ||
|
||
struct Tox_Options *tox_options = tox_options_new(&error_options); | ||
|
||
if (error_options != TOX_ERR_NEW_OK) { | ||
free(buffer); | ||
return -1; | ||
} | ||
|
||
// pass test data to Tox | ||
tox_options_set_savedata_data(tox_options, buffer, filelen); | ||
tox_options_set_savedata_type(tox_options, TOX_SAVEDATA_TYPE_TOX_SAVE); | ||
|
||
TOX_ERR_NEW error_new = 0; | ||
Tox *tox = tox_new(tox_options, &error_new); | ||
|
||
if (tox == NULL || error_new != TOX_ERR_NEW_OK) { | ||
free(buffer); | ||
return -1; | ||
} | ||
|
||
tox_kill(tox); | ||
free(buffer); | ||
|
||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#! /bin/sh | ||
|
||
# move to repo root | ||
cd ../ | ||
rm -R _afl_build | ||
mkdir _afl_build | ||
cd _afl_build | ||
|
||
# build c-toxcore using afl instrumentation | ||
cmake -DCMAKE_C_COMPILER=afl-clang -DBUILD_MISC_TESTS=ON .. | ||
make | ||
|
||
# start fuzzing | ||
afl-fuzz -i ../testing/afl_testdata/tox_saves/ -o afl_out/ ./afl_toxsave @@ |