forked from OSchip/llvm-project
[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:
parent
12286d22b7
commit
2d1d944f7e
|
@ -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
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue