aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Kliuchnikov <eustas@google.com>2018-06-18 14:39:38 +0200
committerGitHub <noreply@github.com>2018-06-18 14:39:38 +0200
commit7505290ef9880ae636a57f57caf77a8dac56d283 (patch)
treef7f1984ff614654d0e9e8f51c460fe49d7e56c4a
parentff05c35166eef5048ff3da640f7e0ba00f937507 (diff)
downloadbrotli-7505290ef9880ae636a57f57caf77a8dac56d283.zip
brotli-7505290ef9880ae636a57f57caf77a8dac56d283.tar.gz
brotli-7505290ef9880ae636a57f57caf77a8dac56d283.tar.bz2
Convert fuzzer to C99. (#686)
-rw-r--r--c/fuzz/decode_fuzzer.c (renamed from c/fuzz/decode_fuzzer.cc)11
-rw-r--r--c/fuzz/run_decode_fuzzer.c (renamed from c/fuzz/run_decode_fuzzer.cc)2
-rwxr-xr-xc/fuzz/test_fuzzer.sh7
3 files changed, 12 insertions, 8 deletions
diff --git a/c/fuzz/decode_fuzzer.cc b/c/fuzz/decode_fuzzer.c
index 60c6f8e..46144e0 100644
--- a/c/fuzz/decode_fuzzer.cc
+++ b/c/fuzz/decode_fuzzer.c
@@ -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;
}
diff --git a/c/fuzz/run_decode_fuzzer.cc b/c/fuzz/run_decode_fuzzer.c
index 8fd4189..c84f98a 100644
--- a/c/fuzz/run_decode_fuzzer.cc
+++ b/c/fuzz/run_decode_fuzzer.c
@@ -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) {
diff --git a/c/fuzz/test_fuzzer.sh b/c/fuzz/test_fuzzer.sh
index 5c754e1..9985194 100755
--- a/c/fuzz/test_fuzzer.sh
+++ b/c/fuzz/test_fuzzer.sh
@@ -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