using pcre2's own fuzzer

This commit is contained in:
Mike Aizatsky 2016-10-31 13:07:50 -07:00
parent ee0e3f2a05
commit b770674426
3 changed files with 5 additions and 27 deletions

View File

@ -19,4 +19,4 @@ MAINTAINER kcc@google.com
RUN apt-get install -y make autoconf automake libtool subversion
RUN svn co svn://vcs.exim.org/pcre2/code/trunk pcre2
COPY build.sh pcre2_fuzzer.cc /src/
COPY build.sh /src/

View File

@ -19,11 +19,10 @@ cd pcre2
# build the library.
./autogen.sh
./configure --enable-never-backslash-C --with-match-limit=1000 --with-match-limit-recursion=1000
./configure --enable-fuzz-support --enable-never-backslash-C --with-match-limit=1000 --with-match-limit-recursion=1000
make clean all
# Build the target.
$CXX $CXXFLAGS -std=c++11 -I src \
/src/pcre2_fuzzer.cc -o /out/pcre2_fuzzer \
-Wl,--whole-archive .libs/*.a -Wl,-no-whole-archive $FUZZER_LDFLAGS \
-lfuzzer
$CXX $CXXFLAGS -o /out/pcre2_fuzzer \
-lfuzzer .libs/libpcre2-fuzzsupport.a .libs/libpcre2-8.a \
$FUZZER_LDFLAGS

View File

@ -1,21 +0,0 @@
// Copyright 2016 Google Inc. All Rights Reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
#include <string>
#include "pcre2posix.h"
using std::string;
extern "C" int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size) {
if (size < 1) return 0;
regex_t preg;
string str(reinterpret_cast<const char*>(data), size);
string pat(str);
int flags = data[size/2] - 'a'; // Make it 0 when the byte is 'a'.
if (0 == regcomp(&preg, pat.c_str(), flags)) {
regmatch_t pmatch[5];
regexec(&preg, str.c_str(), 5, pmatch, 0);
regfree(&preg);
}
return 0;
}