Commit 4da26845 authored by yangguo's avatar yangguo Committed by Commit bot

[regexp, fuzzer] improve regexp fuzzer coverage.

R=jochen@chromium.org, machenbach@chromium.org
BUG=chromium:577261
LOG=N

Review URL: https://codereview.chromium.org/1660463002

Cr-Commit-Position: refs/heads/master@{#33661}
parent 8c04a35c
...@@ -14,6 +14,12 @@ ...@@ -14,6 +14,12 @@
namespace i = v8::internal; namespace i = v8::internal;
void Test(v8::Isolate* isolate, i::Handle<i::JSRegExp> regexp,
i::Handle<i::String> subject, i::Handle<i::JSArray> results_array) {
v8::TryCatch try_catch(isolate);
USE(i::RegExpImpl::Exec(regexp, subject, 0, results_array));
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get(); v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get();
v8::Isolate* isolate = support->GetIsolate(); v8::Isolate* isolate = support->GetIsolate();
...@@ -42,7 +48,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { ...@@ -42,7 +48,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
const uint8_t one_byte_array[6] = {'f', 'o', 'o', 'b', 'a', 'r'}; const uint8_t one_byte_array[6] = {'f', 'o', 'o', 'b', 'a', 'r'};
const i::uc16 two_byte_array[6] = {'f', 0xD83D, 0xDCA9, 'b', 'a', 0x2603}; const i::uc16 two_byte_array[6] = {'f', 0xD83D, 0xDCA9, 'b', 'a', 0x2603};
i::Handle<i::JSArray> results_array = factory->NewJSArray(4); i::Handle<i::JSArray> results_array = factory->NewJSArray(5);
i::Handle<i::String> one_byte = i::Handle<i::String> one_byte =
factory->NewStringFromOneByte(i::Vector<const uint8_t>(one_byte_array, 6)) factory->NewStringFromOneByte(i::Vector<const uint8_t>(one_byte_array, 6))
.ToHandleChecked(); .ToHandleChecked();
...@@ -51,13 +57,17 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { ...@@ -51,13 +57,17 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
.ToHandleChecked(); .ToHandleChecked();
for (int flags = 0; flags <= kAllFlags; flags++) { for (int flags = 0; flags <= kAllFlags; flags++) {
v8::TryCatch try_catch(isolate);
i::MaybeHandle<i::JSRegExp> maybe_regexp =
i::JSRegExp::New(source, static_cast<i::JSRegExp::Flags>(flags));
i::Handle<i::JSRegExp> regexp; i::Handle<i::JSRegExp> regexp;
if (!maybe_regexp.ToHandle(&regexp)) continue; {
USE(i::RegExpImpl::Exec(regexp, one_byte, 0, results_array).is_null() && v8::TryCatch try_catch(isolate);
i::RegExpImpl::Exec(regexp, two_byte, 0, results_array).is_null()); i::MaybeHandle<i::JSRegExp> maybe_regexp =
i::JSRegExp::New(source, static_cast<i::JSRegExp::Flags>(flags));
if (!maybe_regexp.ToHandle(&regexp)) continue;
}
Test(isolate, regexp, one_byte, results_array);
Test(isolate, regexp, two_byte, results_array);
Test(isolate, regexp, factory->empty_string(), results_array);
Test(isolate, regexp, source, results_array);
} }
return 0; return 0;
......
...@@ -8,6 +8,15 @@ from testrunner.local import testsuite ...@@ -8,6 +8,15 @@ from testrunner.local import testsuite
from testrunner.objects import testcase from testrunner.objects import testcase
class FuzzerVariantGenerator(testsuite.VariantGenerator):
# Only run the fuzzer with standard variant.
def FilterVariantsByTest(self, testcase):
return self.standard_variant
def GetFlagSets(self, testcase, variant):
return testsuite.FAST_VARIANT_FLAGS[variant]
class FuzzerTestSuite(testsuite.TestSuite): class FuzzerTestSuite(testsuite.TestSuite):
SUB_TESTS = ( 'parser', 'regexp', ) SUB_TESTS = ( 'parser', 'regexp', )
...@@ -31,6 +40,9 @@ class FuzzerTestSuite(testsuite.TestSuite): ...@@ -31,6 +40,9 @@ class FuzzerTestSuite(testsuite.TestSuite):
suite, name = testcase.path.split('/') suite, name = testcase.path.split('/')
return [os.path.join(self.root, suite, name)] return [os.path.join(self.root, suite, name)]
def _VariantGeneratorFactory(self):
return FuzzerVariantGenerator
def GetSuite(name, root): def GetSuite(name, root):
return FuzzerTestSuite(name, root) return FuzzerTestSuite(name, root)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment