-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add fuzz target * update fuzzer * add fuzzer to build with basic entry point * add build script * cleanup * build fuzz target using cmake in oss-fuzz env * ossfuzz.sh add newline * update build
- Loading branch information
Showing
4 changed files
with
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
|
||
/* Fuzz target entry point, works without libFuzzer */ | ||
|
||
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
FILE *f; | ||
char *buf = NULL; | ||
long siz_buf; | ||
|
||
if(argc < 2) | ||
{ | ||
fprintf(stderr, "no input file\n"); | ||
goto err; | ||
} | ||
|
||
f = fopen(argv[1], "rb"); | ||
if(f == NULL) | ||
{ | ||
fprintf(stderr, "error opening input file %s\n", argv[1]); | ||
goto err; | ||
} | ||
|
||
fseek(f, 0, SEEK_END); | ||
|
||
siz_buf = ftell(f); | ||
rewind(f); | ||
|
||
if(siz_buf < 1) goto err; | ||
|
||
buf = (char*)malloc(siz_buf); | ||
if(buf == NULL) | ||
{ | ||
fprintf(stderr, "malloc() failed\n"); | ||
goto err; | ||
} | ||
|
||
if(fread(buf, siz_buf, 1, f) != 1) | ||
{ | ||
fprintf(stderr, "fread() failed\n"); | ||
goto err; | ||
} | ||
|
||
(void)LLVMFuzzerTestOneInput((uint8_t*)buf, siz_buf); | ||
|
||
err: | ||
free(buf); | ||
|
||
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,16 @@ | ||
#include <utf8proc.h> | ||
|
||
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) | ||
{ | ||
if(size < 1) return 0; | ||
|
||
if(data[size-1] != '\0') return 0; | ||
|
||
free(utf8proc_NFD(data)); | ||
free(utf8proc_NFC(data)); | ||
free(utf8proc_NFKD(data)); | ||
free(utf8proc_NFKC(data)); | ||
free(utf8proc_NFKC_Casefold(data)); | ||
|
||
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,13 @@ | ||
#!/bin/bash -eu | ||
# This script is meant to be run by | ||
# https://github.com/google/oss-fuzz/blob/master/projects/utf8proc/Dockerfile | ||
|
||
mkdir build | ||
cd build | ||
cmake .. -DUTF8PROC_ENABLE_TESTING=ON -DLIB_FUZZING_ENGINE="$LIB_FUZZING_ENGINE" | ||
make -j$(nproc) | ||
|
||
cp $SRC/utf8proc/build/fuzzer utf8proc_fuzzer | ||
|
||
find $SRC/utf8proc/test -name "*.txt" | \ | ||
xargs zip $OUT/utf8proc_fuzzer_seed_corpus.zip |