| 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 "net/url_request/url_request.h" | 5 #include "net/url_request/url_request.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/logging.h" |
| 12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 13 #include "base/test/fuzzed_data_provider.h" | 14 #include "base/test/fuzzed_data_provider.h" |
| 14 #include "net/base/request_priority.h" | 15 #include "net/base/request_priority.h" |
| 15 #include "net/socket/fuzzed_socket_factory.h" | 16 #include "net/socket/fuzzed_socket_factory.h" |
| 16 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
| 17 #include "net/url_request/url_request_context.h" | 18 #include "net/url_request/url_request_context.h" |
| 18 #include "net/url_request/url_request_test_util.h" | 19 #include "net/url_request/url_request_test_util.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 22 struct Environment { |
| 23 Environment() { |
| 24 // Disable noisy logging as per "libFuzzer in Chrome" documentation: |
| 25 // testing/libfuzzer/getting_started.md#Disable-noisy-error-message-logging. |
| 26 logging::SetMinLogLevel(logging::LOG_FATAL); |
| 27 } |
| 28 }; |
| 29 |
| 30 Environment* env = new Environment(); |
| 31 |
| 21 // Integration fuzzer for URLRequest's handling of HTTP requests. Can follow | 32 // Integration fuzzer for URLRequest's handling of HTTP requests. Can follow |
| 22 // redirects, both on the same server (using a new socket or the old one) and | 33 // redirects, both on the same server (using a new socket or the old one) and |
| 23 // across servers. | 34 // across servers. |
| 24 // TODO(mmenke): Add support for testing HTTPS, auth, proxies, uploading, | 35 // TODO(mmenke): Add support for testing HTTPS, auth, proxies, uploading, |
| 25 // cancelation, deferring reads / redirects, using preconnected sockets, SPDY, | 36 // cancelation, deferring reads / redirects, using preconnected sockets, SPDY, |
| 26 // QUIC, DNS failures (they all currently resolve to localhost), IPv6 DNS | 37 // QUIC, DNS failures (they all currently resolve to localhost), IPv6 DNS |
| 27 // results, URLs with IPs instead of hostnames (v4 and v6), etc. | 38 // results, URLs with IPs instead of hostnames (v4 and v6), etc. |
| 28 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 39 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 29 base::FuzzedDataProvider data_provider(data, size); | 40 base::FuzzedDataProvider data_provider(data, size); |
| 30 net::TestURLRequestContext url_request_context(true); | 41 net::TestURLRequestContext url_request_context(true); |
| 31 net::FuzzedSocketFactory fuzzed_socket_factory(&data_provider); | 42 net::FuzzedSocketFactory fuzzed_socket_factory(&data_provider); |
| 32 url_request_context.set_client_socket_factory(&fuzzed_socket_factory); | 43 url_request_context.set_client_socket_factory(&fuzzed_socket_factory); |
| 33 url_request_context.Init(); | 44 url_request_context.Init(); |
| 34 | 45 |
| 35 net::TestDelegate delegate; | 46 net::TestDelegate delegate; |
| 36 | 47 |
| 37 std::unique_ptr<net::URLRequest> url_request( | 48 std::unique_ptr<net::URLRequest> url_request( |
| 38 url_request_context.CreateRequest(GURL("http://foo/"), | 49 url_request_context.CreateRequest(GURL("http://foo/"), |
| 39 net::DEFAULT_PRIORITY, &delegate)); | 50 net::DEFAULT_PRIORITY, &delegate)); |
| 40 url_request->Start(); | 51 url_request->Start(); |
| 41 // TestDelegate quits the message loop on completion. | 52 // TestDelegate quits the message loop on completion. |
| 42 base::RunLoop().Run(); | 53 base::RunLoop().Run(); |
| 43 return 0; | 54 return 0; |
| 44 } | 55 } |
| OLD | NEW |