| 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 <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/fuzzed_data_provider.h" |
| 8 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 9 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 10 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 11 #include "net/base/fuzzed_data_provider.h" | |
| 12 #include "net/http/http_request_headers.h" | 12 #include "net/http/http_request_headers.h" |
| 13 #include "net/url_request/data_protocol_handler.h" | 13 #include "net/url_request/data_protocol_handler.h" |
| 14 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
| 15 #include "net/url_request/url_request_job_factory_impl.h" | 15 #include "net/url_request/url_request_job_factory_impl.h" |
| 16 #include "net/url_request/url_request_test_util.h" | 16 #include "net/url_request/url_request_test_util.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 const size_t kMaxLengthForFuzzedRange = 32; | 20 const size_t kMaxLengthForFuzzedRange = 32; |
| 21 | 21 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 33 "data", base::WrapUnique(new net::DataProtocolHandler())); | 33 "data", base::WrapUnique(new net::DataProtocolHandler())); |
| 34 context_.set_job_factory(&job_factory_); | 34 context_.set_job_factory(&job_factory_); |
| 35 context_.Init(); | 35 context_.Init(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 static URLRequestDataJobFuzzerHarness* GetInstance() { | 38 static URLRequestDataJobFuzzerHarness* GetInstance() { |
| 39 return base::Singleton<URLRequestDataJobFuzzerHarness>::get(); | 39 return base::Singleton<URLRequestDataJobFuzzerHarness>::get(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 int CreateAndReadFromDataURLRequest(const uint8_t* data, size_t size) { | 42 int CreateAndReadFromDataURLRequest(const uint8_t* data, size_t size) { |
| 43 net::FuzzedDataProvider provider(data, size); | 43 base::FuzzedDataProvider provider(data, size); |
| 44 read_lengths_.clear(); | 44 read_lengths_.clear(); |
| 45 | 45 |
| 46 // Allocate an IOBuffer with fuzzed size. | 46 // Allocate an IOBuffer with fuzzed size. |
| 47 uint32_t buf_size = provider.ConsumeUint32InRange(1, 127); // 7 bits. | 47 uint32_t buf_size = provider.ConsumeUint32InRange(1, 127); // 7 bits. |
| 48 scoped_refptr<net::IOBuffer> buf( | 48 scoped_refptr<net::IOBuffer> buf( |
| 49 new net::IOBuffer(static_cast<size_t>(buf_size))); | 49 new net::IOBuffer(static_cast<size_t>(buf_size))); |
| 50 buf_.swap(buf); | 50 buf_.swap(buf); |
| 51 | 51 |
| 52 // Generate a range header, and a bool determining whether to use it. | 52 // Generate a range header, and a bool determining whether to use it. |
| 53 // Generate the header regardless of the bool value to keep the data URL and | 53 // Generate the header regardless of the bool value to keep the data URL and |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 base::RunLoop* read_loop_; | 162 base::RunLoop* read_loop_; |
| 163 | 163 |
| 164 DISALLOW_COPY_AND_ASSIGN(URLRequestDataJobFuzzerHarness); | 164 DISALLOW_COPY_AND_ASSIGN(URLRequestDataJobFuzzerHarness); |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 167 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 168 // Using a static singleton test harness lets the test run ~3-4x faster. | 168 // Using a static singleton test harness lets the test run ~3-4x faster. |
| 169 return URLRequestDataJobFuzzerHarness::GetInstance() | 169 return URLRequestDataJobFuzzerHarness::GetInstance() |
| 170 ->CreateAndReadFromDataURLRequest(data, size); | 170 ->CreateAndReadFromDataURLRequest(data, size); |
| 171 } | 171 } |
| OLD | NEW |