Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: net/url_request/url_request_ftp_fuzzer.cc

Issue 2469813002: Add a URLRequest FTP fuzzer. (Closed)
Patch Set: merge Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/socket/fuzzed_socket.cc ('k') | net/url_request/url_request_fuzzer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/url_request/url_request.h"
6
7 #include <stddef.h>
8 #include <stdint.h>
9
10 #include <memory>
11
12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h"
14 #include "base/run_loop.h"
15 #include "base/test/fuzzed_data_provider.h"
16 #include "net/base/request_priority.h"
17 #include "net/dns/fuzzed_host_resolver.h"
18 #include "net/ftp/ftp_network_transaction.h"
19 #include "net/ftp/ftp_transaction_factory.h"
20 #include "net/socket/client_socket_factory.h"
21 #include "net/socket/fuzzed_socket_factory.h"
22 #include "net/url_request/ftp_protocol_handler.h"
23 #include "net/url_request/url_request.h"
24 #include "net/url_request/url_request_context.h"
25 #include "net/url_request/url_request_job_factory_impl.h"
26 #include "net/url_request/url_request_test_util.h"
27 #include "url/gurl.h"
28
29 namespace {
30
31 // Returns FtpNetworkTransactions using the specified HostResolver
32 // and ClientSocketFactory.
33 class FuzzedFtpTransactionFactory : public net::FtpTransactionFactory {
34 public:
35 FuzzedFtpTransactionFactory(net::HostResolver* host_resolver,
36 net::ClientSocketFactory* client_socket_factory)
37 : host_resolver_(host_resolver),
38 client_socket_factory_(client_socket_factory) {}
39
40 // FtpTransactionFactory:
41 std::unique_ptr<net::FtpTransaction> CreateTransaction() override {
42 return base::MakeUnique<net::FtpNetworkTransaction>(host_resolver_,
43 client_socket_factory_);
44 }
45
46 void Suspend(bool suspend) override { NOTREACHED(); }
47
48 private:
49 net::HostResolver* host_resolver_;
50 net::ClientSocketFactory* client_socket_factory_;
51
52 DISALLOW_COPY_AND_ASSIGN(FuzzedFtpTransactionFactory);
53 };
54
55 } // namespace
56
57 // Integration fuzzer for URLRequestFtpJob.
58 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
59 base::FuzzedDataProvider data_provider(data, size);
60 net::TestURLRequestContext url_request_context(true);
61 net::FuzzedSocketFactory fuzzed_socket_factory(&data_provider);
62 url_request_context.set_client_socket_factory(&fuzzed_socket_factory);
63
64 // Need to fuzz the HostResolver to select between IPv4 and IPv6.
65 net::FuzzedHostResolver host_resolver(net::HostResolver::Options(), nullptr,
66 &data_provider);
67 url_request_context.set_host_resolver(&host_resolver);
68
69 net::URLRequestJobFactoryImpl job_factory;
70 job_factory.SetProtocolHandler(
71 "ftp", net::FtpProtocolHandler::CreateForTesting(
72 base::MakeUnique<FuzzedFtpTransactionFactory>(
73 &host_resolver, &fuzzed_socket_factory)));
74 url_request_context.set_job_factory(&job_factory);
75
76 url_request_context.Init();
77
78 net::TestDelegate delegate;
79
80 std::unique_ptr<net::URLRequest> url_request(
81 url_request_context.CreateRequest(
82 GURL("ftp://foo/" + data_provider.ConsumeRandomLengthString(1000)),
83 net::DEFAULT_PRIORITY, &delegate));
84 url_request->Start();
85 // TestDelegate quits the message loop on completion.
86 base::RunLoop().Run();
87
88 return 0;
89 }
OLDNEW
« no previous file with comments | « net/socket/fuzzed_socket.cc ('k') | net/url_request/url_request_fuzzer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698