| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium 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 "platform/SharedBuffer.h" | 5 #include "platform/SharedBuffer.h" |
| 6 #include "platform/heap/Handle.h" | 6 #include "platform/heap/Handle.h" |
| 7 #include "platform/mhtml/ArchiveResource.h" | 7 #include "platform/mhtml/ArchiveResource.h" |
| 8 #include "platform/mhtml/MHTMLParser.h" | 8 #include "platform/mhtml/MHTMLParser.h" |
| 9 #include "platform/testing/TestingPlatformSupport.h" | 9 #include "platform/testing/BlinkFuzzerTestSupport.h" |
| 10 #include "wtf/Assertions.h" | |
| 11 #include "wtf/Compiler.h" | |
| 12 #include <memory> | |
| 13 #include <stddef.h> | 10 #include <stddef.h> |
| 14 #include <stdint.h> | 11 #include <stdint.h> |
| 15 | 12 |
| 16 namespace blink { | 13 namespace blink { |
| 17 | 14 |
| 18 // Fuzzer for blink::MHTMLParser. | 15 // Fuzzer for blink::MHTMLParser. |
| 19 int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 16 int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 20 MHTMLParser mhtmlParser(SharedBuffer::create(data, size)); | 17 MHTMLParser mhtmlParser(SharedBuffer::create(data, size)); |
| 21 HeapVector<Member<ArchiveResource>> mhtmlArchives = | 18 HeapVector<Member<ArchiveResource>> mhtmlArchives = |
| 22 mhtmlParser.parseArchive(); | 19 mhtmlParser.parseArchive(); |
| 23 mhtmlArchives.clear(); | 20 mhtmlArchives.clear(); |
| 24 ThreadState::current()->collectAllGarbage(); | 21 ThreadState::current()->collectAllGarbage(); |
| 25 | 22 |
| 26 return 0; | 23 return 0; |
| 27 } | 24 } |
| 28 | 25 |
| 29 } // namespace blink | 26 } // namespace blink |
| 30 | 27 |
| 31 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 28 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 32 return blink::LLVMFuzzerTestOneInput(data, size); | 29 return blink::LLVMFuzzerTestOneInput(data, size); |
| 33 } | 30 } |
| 34 | 31 |
| 35 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { | 32 extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { |
| 36 // Intentional leak - no need to do cleanup as explained in | 33 blink::InitializeBlinkFuzzTest(argc, argv); |
| 37 // "Initialization/Cleanup" section of testing/libfuzzer/efficient_fuzzer.md | |
| 38 DEFINE_STATIC_LOCAL(blink::ScopedUnittestsEnvironmentSetup, testSetup, | |
| 39 (*argc, *argv)); | |
| 40 ALLOW_UNUSED_LOCAL(testSetup); | |
| 41 | |
| 42 return 0; | 34 return 0; |
| 43 } | 35 } |
| OLD | NEW |