| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <limits.h> | 5 #include <limits.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "include/v8.h" | 9 #include "include/v8.h" |
| 10 #include "src/factory.h" | 10 #include "src/factory.h" |
| 11 #include "src/objects-inl.h" | 11 #include "src/objects-inl.h" |
| 12 #include "src/objects.h" | 12 #include "src/objects.h" |
| 13 #include "src/regexp/jsregexp.h" | 13 #include "src/regexp/jsregexp.h" |
| 14 #include "test/fuzzer/fuzzer-support.h" | 14 #include "test/fuzzer/fuzzer-support.h" |
| 15 | 15 |
| 16 namespace i = v8::internal; | 16 namespace i = v8::internal; |
| 17 | 17 |
| 18 void Test(v8::Isolate* isolate, i::Handle<i::JSRegExp> regexp, | 18 void Test(v8::Isolate* isolate, i::Handle<i::JSRegExp> regexp, |
| 19 i::Handle<i::String> subject, i::Handle<i::JSArray> results_array) { | 19 i::Handle<i::String> subject, |
| 20 i::Handle<i::RegExpMatchInfo> results_array) { |
| 20 v8::TryCatch try_catch(isolate); | 21 v8::TryCatch try_catch(isolate); |
| 21 USE(i::RegExpImpl::Exec(regexp, subject, 0, results_array)); | 22 USE(i::RegExpImpl::Exec(regexp, subject, 0, results_array)); |
| 22 } | 23 } |
| 23 | 24 |
| 24 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 25 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 25 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get(); | 26 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get(); |
| 26 v8::Isolate* isolate = support->GetIsolate(); | 27 v8::Isolate* isolate = support->GetIsolate(); |
| 27 | 28 |
| 28 v8::Isolate::Scope isolate_scope(isolate); | 29 v8::Isolate::Scope isolate_scope(isolate); |
| 29 v8::HandleScope handle_scope(isolate); | 30 v8::HandleScope handle_scope(isolate); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 41 i::Handle<i::String> source; | 42 i::Handle<i::String> source; |
| 42 if (!maybe_source.ToHandle(&source)) return 0; | 43 if (!maybe_source.ToHandle(&source)) return 0; |
| 43 | 44 |
| 44 static const int kAllFlags = i::JSRegExp::kGlobal | i::JSRegExp::kIgnoreCase | | 45 static const int kAllFlags = i::JSRegExp::kGlobal | i::JSRegExp::kIgnoreCase | |
| 45 i::JSRegExp::kMultiline | i::JSRegExp::kSticky | | 46 i::JSRegExp::kMultiline | i::JSRegExp::kSticky | |
| 46 i::JSRegExp::kUnicode; | 47 i::JSRegExp::kUnicode; |
| 47 | 48 |
| 48 const uint8_t one_byte_array[6] = {'f', 'o', 'o', 'b', 'a', 'r'}; | 49 const uint8_t one_byte_array[6] = {'f', 'o', 'o', 'b', 'a', 'r'}; |
| 49 const i::uc16 two_byte_array[6] = {'f', 0xD83D, 0xDCA9, 'b', 'a', 0x2603}; | 50 const i::uc16 two_byte_array[6] = {'f', 0xD83D, 0xDCA9, 'b', 'a', 0x2603}; |
| 50 | 51 |
| 51 i::Handle<i::JSArray> results_array = factory->NewJSArray(5); | 52 i::Handle<i::RegExpMatchInfo> results_array = factory->NewRegExpMatchInfo(); |
| 52 i::Handle<i::String> one_byte = | 53 i::Handle<i::String> one_byte = |
| 53 factory->NewStringFromOneByte(i::Vector<const uint8_t>(one_byte_array, 6)) | 54 factory->NewStringFromOneByte(i::Vector<const uint8_t>(one_byte_array, 6)) |
| 54 .ToHandleChecked(); | 55 .ToHandleChecked(); |
| 55 i::Handle<i::String> two_byte = | 56 i::Handle<i::String> two_byte = |
| 56 factory->NewStringFromTwoByte(i::Vector<const i::uc16>(two_byte_array, 6)) | 57 factory->NewStringFromTwoByte(i::Vector<const i::uc16>(two_byte_array, 6)) |
| 57 .ToHandleChecked(); | 58 .ToHandleChecked(); |
| 58 | 59 |
| 59 for (int flags = 0; flags <= kAllFlags; flags++) { | 60 for (int flags = 0; flags <= kAllFlags; flags++) { |
| 60 i::Handle<i::JSRegExp> regexp; | 61 i::Handle<i::JSRegExp> regexp; |
| 61 { | 62 { |
| 62 v8::TryCatch try_catch(isolate); | 63 v8::TryCatch try_catch(isolate); |
| 63 i::MaybeHandle<i::JSRegExp> maybe_regexp = | 64 i::MaybeHandle<i::JSRegExp> maybe_regexp = |
| 64 i::JSRegExp::New(source, static_cast<i::JSRegExp::Flags>(flags)); | 65 i::JSRegExp::New(source, static_cast<i::JSRegExp::Flags>(flags)); |
| 65 if (!maybe_regexp.ToHandle(®exp)) { | 66 if (!maybe_regexp.ToHandle(®exp)) { |
| 66 i_isolate->clear_pending_exception(); | 67 i_isolate->clear_pending_exception(); |
| 67 continue; | 68 continue; |
| 68 } | 69 } |
| 69 } | 70 } |
| 70 Test(isolate, regexp, one_byte, results_array); | 71 Test(isolate, regexp, one_byte, results_array); |
| 71 Test(isolate, regexp, two_byte, results_array); | 72 Test(isolate, regexp, two_byte, results_array); |
| 72 Test(isolate, regexp, factory->empty_string(), results_array); | 73 Test(isolate, regexp, factory->empty_string(), results_array); |
| 73 Test(isolate, regexp, source, results_array); | 74 Test(isolate, regexp, source, results_array); |
| 74 } | 75 } |
| 75 | 76 |
| 76 isolate->RequestGarbageCollectionForTesting( | 77 isolate->RequestGarbageCollectionForTesting( |
| 77 v8::Isolate::kFullGarbageCollection); | 78 v8::Isolate::kFullGarbageCollection); |
| 78 return 0; | 79 return 0; |
| 79 } | 80 } |
| OLD | NEW |