Convert fuzzer to C99. (#686)

This commit is contained in:
Eugene Kliuchnikov 2018-06-18 14:39:38 +02:00 committed by GitHub
parent ff05c35166
commit 7505290ef9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 8 deletions

View File

@ -4,18 +4,23 @@
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <brotli/decode.h>
// Entry point for LibFuzzer.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
size_t addend = 0;
if (size > 0)
addend = data[size - 1] & 7;
const uint8_t* next_in = data;
const int kBufferSize = 1024;
uint8_t* buffer = new uint8_t[kBufferSize];
uint8_t* buffer = (uint8_t*) malloc(kBufferSize);
if (!buffer) {
// OOM is out-of-scope here.
return 0;
}
/* The biggest "magic number" in brotli is 16MiB - 16, so no need to check
the cases with much longer output. */
const size_t total_out_limit = (addend == 0) ? (1 << 26) : (1 << 24);
@ -48,6 +53,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
}
BrotliDecoderDestroyInstance(state);
delete[] buffer;
free(buffer);
return 0;
}

View File

@ -11,7 +11,7 @@
#include <stdlib.h>
#include <stdint.h>
extern "C" void LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
void LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
int main(int argc, char* *argv) {
if (argc != 2) {

View File

@ -2,7 +2,6 @@
set -e
export CC=${CC:-cc}
export CXX=${CXX:-c++}
BROTLI="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"
SRC=$BROTLI/c
@ -13,12 +12,12 @@ rm -rf bin
mkdir bin
cd bin
cmake $BROTLI -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" \
cmake $BROTLI -DCMAKE_C_COMPILER="$CC" \
-DBUILD_TESTING=OFF -DENABLE_SANITIZER=address
make -j$(nproc) brotlidec-static
${CXX} -o run_decode_fuzzer -std=c++11 -fsanitize=address -I$SRC/include \
$SRC/fuzz/decode_fuzzer.cc $SRC/fuzz/run_decode_fuzzer.cc \
${CC} -o run_decode_fuzzer -std=c99 -fsanitize=address -I$SRC/include \
$SRC/fuzz/decode_fuzzer.c $SRC/fuzz/run_decode_fuzzer.c \
./libbrotlidec-static.a ./libbrotlicommon-static.a
mkdir decode_corpora