1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-22 12:33:33 +02:00

[libFuzzer] first steps in adding a proper automated test suite based on real-life code: add a script to build RE2 at a revision that has known bugs

llvm-svn: 282292
This commit is contained in:
Kostya Serebryany 2016-09-23 20:43:22 +00:00
parent 05bd1d2ffe
commit 75f28537e8
2 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,21 @@
#!/bin/bash
[ -e $(basename $0) ] && echo "PLEASE USE THIS SCRIPT FROM ANOTHER DIR" && exit 1
SCRIPT_DIR=$(dirname $0)
LIBFUZZER_SRC=$(dirname $(dirname $SCRIPT_DIR))
FUZZ_CXXFLAGS="-O2 -g -fsanitize=address -fsanitize-coverage=trace-pc-guard,trace-cmp,trace-gep,trace-div"
get() {
[ ! -e SRC ] && git clone https://github.com/google/re2.git SRC && (cd SRC && git reset --hard 499ef7eff7455ce9c9fae86111d4a77b6ac335de)
}
build_lib() {
rm -rf BUILD
cp -rf SRC BUILD
(cd BUILD && make clean && CXX=clang++ CXXFLAGS="$FUZZ_CXXFLAGS" make -j)
}
get
build_lib
$LIBFUZZER_SRC/build.sh
clang++ -g $SCRIPT_DIR/target.cc -I BUILD BUILD/obj/libre2.a libFuzzer.a $FUZZ_CXXFLAGS

View File

@ -0,0 +1,27 @@
#include <string>
#include "re2/re2.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size < 3) return 0;
uint16_t f = (data[0] << 16) + data[1];
RE2::Options opt;
opt.set_log_errors(false);
if (f & 1) opt.set_encoding(RE2::Options::EncodingLatin1);
opt.set_posix_syntax(f & 2);
opt.set_longest_match(f & 4);
opt.set_literal(f & 8);
opt.set_never_nl(f & 16);
opt.set_dot_nl(f & 32);
opt.set_never_capture(f & 64);
opt.set_case_sensitive(f & 128);
opt.set_perl_classes(f & 256);
opt.set_word_boundary(f & 512);
opt.set_one_line(f & 1024);
const char *b = reinterpret_cast<const char*>(data) + 2;
const char *e = reinterpret_cast<const char*>(data) + size;
std::string s1(b, e);
RE2 re(s1, opt);
if (re.ok())
RE2::FullMatch(s1, re);
return 0;
}