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

Side by Side Diff: net/socket/fuzzed_socket_factory.cc

Issue 1917503002: URLRequest fuzzer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fuzz
Patch Set: Update other fuzzers (Lost them in a merge) Created 4 years, 8 months 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
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/socket/fuzzed_socket_factory.h"
6
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "net/base/address_list.h"
10 #include "net/base/ip_endpoint.h"
11 #include "net/base/net_errors.h"
12 #include "net/base/network_change_notifier.h"
13 #include "net/log/net_log.h"
14 #include "net/socket/connection_attempts.h"
15 #include "net/socket/fuzzed_socket.h"
16 #include "net/socket/ssl_client_socket.h"
17 #include "net/ssl/ssl_failure_state.h"
18 #include "net/udp/datagram_client_socket.h"
19
20 namespace net {
21
22 namespace {
23
24 // Datagram ClientSocket implementation that always failed to connect.
25 class FailingUDPClientSocket : public DatagramClientSocket {
26 public:
27 FailingUDPClientSocket() {}
eroman 2016/04/22 22:07:11 This looks boring.
mmenke 2016/04/25 15:09:19 It was, very.
28 ~FailingUDPClientSocket() override {}
29
30 // DatagramClientSocket implementation:
31 int Connect(const IPEndPoint& address) override { return ERR_FAILED; }
32
33 int ConnectUsingNetwork(NetworkChangeNotifier::NetworkHandle network,
34 const IPEndPoint& address) override {
35 return ERR_FAILED;
36 }
37
38 int ConnectUsingDefaultNetwork(const IPEndPoint& address) override {
39 return ERR_FAILED;
40 }
41
42 NetworkChangeNotifier::NetworkHandle GetBoundNetwork() const override {
43 return -1;
44 }
45
46 // DatagramSocket implementation:
47 void Close() override {}
48
49 int GetPeerAddress(IPEndPoint* address) const override {
50 return ERR_SOCKET_NOT_CONNECTED;
51 }
52
53 int GetLocalAddress(IPEndPoint* address) const override {
54 return ERR_SOCKET_NOT_CONNECTED;
55 }
56
57 const BoundNetLog& NetLog() const override { return net_log_; }
58
59 // Socket implementation:
60 int Read(IOBuffer* buf,
61 int buf_len,
62 const CompletionCallback& callback) override {
63 NOTREACHED();
64 return ERR_UNEXPECTED;
65 }
66
67 int Write(IOBuffer* buf,
68 int buf_len,
69 const CompletionCallback& callback) override {
70 NOTREACHED();
71 return ERR_UNEXPECTED;
72 }
73
74 int SetReceiveBufferSize(int32_t size) override {
75 NOTREACHED();
76 return ERR_UNEXPECTED;
77 }
78
79 int SetSendBufferSize(int32_t size) override {
80 NOTREACHED();
81 return ERR_UNEXPECTED;
82 }
83
84 BoundNetLog net_log_;
85
86 DISALLOW_COPY_AND_ASSIGN(FailingUDPClientSocket);
87 };
88
89 // SSLClientSocket implementation that always fails to connect.
90 class FailingSSLClientSocket : public SSLClientSocket {
eroman 2016/04/22 22:07:11 Also bored.
91 public:
92 FailingSSLClientSocket() {}
93 ~FailingSSLClientSocket() override {}
94
95 // Socket implementation:
96 int Read(IOBuffer* buf,
97 int buf_len,
98 const CompletionCallback& callback) override {
99 NOTREACHED();
100 return ERR_UNEXPECTED;
101 }
102
103 int Write(IOBuffer* buf,
104 int buf_len,
105 const CompletionCallback& callback) override {
106 NOTREACHED();
107 return ERR_UNEXPECTED;
108 }
109
110 int SetReceiveBufferSize(int32_t size) override { return OK; }
111 int SetSendBufferSize(int32_t size) override { return OK; }
112
113 // StreamSocket implementation:
114 int Connect(const CompletionCallback& callback) override {
115 return ERR_FAILED;
116 }
117
118 void Disconnect() override {}
119 bool IsConnected() const override { return false; }
120 bool IsConnectedAndIdle() const override { return false; }
121
122 int GetPeerAddress(IPEndPoint* address) const override {
123 return ERR_SOCKET_NOT_CONNECTED;
124 }
125 int GetLocalAddress(IPEndPoint* address) const override {
126 return ERR_SOCKET_NOT_CONNECTED;
127 }
128
129 const BoundNetLog& NetLog() const override { return net_log_; }
130
131 void SetSubresourceSpeculation() override {}
132 void SetOmniboxSpeculation() override {}
133
134 bool WasEverUsed() const override { return false; }
135
136 void EnableTCPFastOpenIfSupported() override {}
137
138 bool WasNpnNegotiated() const override { return false; }
139
140 NextProto GetNegotiatedProtocol() const override { return kProtoUnknown; }
141
142 bool GetSSLInfo(SSLInfo* ssl_info) override { return false; }
143
144 void GetConnectionAttempts(ConnectionAttempts* out) const override {
145 out->clear();
146 }
147
148 void ClearConnectionAttempts() override {}
149
150 void AddConnectionAttempts(const ConnectionAttempts& attempts) override {}
151
152 int64_t GetTotalReceivedBytes() const override { return 0; }
153
154 // SSLSocket implementation:
155 int ExportKeyingMaterial(const base::StringPiece& label,
156 bool has_context,
157 const base::StringPiece& context,
158 unsigned char* out,
159 unsigned int outlen) override {
160 NOTREACHED();
161 return 0;
162 }
163
164 // SSLClientSocket implementation:
165 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override {}
166
167 NextProtoStatus GetNextProto(std::string* proto) const override {
168 return NextProtoStatus::kNextProtoUnsupported;
169 }
170
171 ChannelIDService* GetChannelIDService() const override {
172 NOTREACHED();
173 return nullptr;
174 }
175
176 Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key,
177 std::vector<uint8_t>* out) override {
178 NOTREACHED();
179 return ERR_UNEXPECTED;
180 }
181
182 crypto::ECPrivateKey* GetChannelIDKey() const override {
183 NOTREACHED();
184 return nullptr;
185 }
186
187 SSLFailureState GetSSLFailureState() const override {
188 return SSL_FAILURE_UNKNOWN;
189 }
190
191 private:
192 BoundNetLog net_log_;
193
194 DISALLOW_COPY_AND_ASSIGN(FailingSSLClientSocket);
195 };
196
197 } // namespace
198
199 FuzzedSocketFactory::FuzzedSocketFactory(FuzzedDataProvider* data_provider)
200 : data_provider_(data_provider) {}
201
202 FuzzedSocketFactory::~FuzzedSocketFactory() {}
203
204 std::unique_ptr<DatagramClientSocket>
205 FuzzedSocketFactory::CreateDatagramClientSocket(
206 DatagramSocket::BindType bind_type,
207 const RandIntCallback& rand_int_cb,
208 NetLog* net_log,
209 const NetLog::Source& source) {
210 return make_scoped_ptr(new FailingUDPClientSocket());
eroman 2016/04/22 22:07:11 The new hotness is WrapUnique(). The documentatio
mmenke 2016/04/27 19:53:25 Done.
211 }
212
213 std::unique_ptr<StreamSocket> FuzzedSocketFactory::CreateTransportClientSocket(
214 const AddressList& addresses,
215 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher,
216 NetLog* net_log,
217 const NetLog::Source& source) {
218 std::unique_ptr<FuzzedSocket> socket(
219 new FuzzedSocket(data_provider_, net_log));
220 socket->set_fuzz_connect_result(true);
221 // Just use the first address.
222 socket->set_remote_address(*addresses.begin());
223 return std::move(socket);
eroman 2016/04/22 22:07:11 Remove the std::move(). Should be sufficient to j
mmenke 2016/04/27 19:53:25 That doesn't work - their types are different (std
224 }
225
226 std::unique_ptr<SSLClientSocket> FuzzedSocketFactory::CreateSSLClientSocket(
227 std::unique_ptr<ClientSocketHandle> transport_socket,
228 const HostPortPair& host_and_port,
229 const SSLConfig& ssl_config,
230 const SSLClientSocketContext& context) {
231 return make_scoped_ptr(new FailingSSLClientSocket());
eroman 2016/04/22 22:07:11 ditto, WrapUnique()
mmenke 2016/04/27 19:53:25 Done.
232 }
233
234 void FuzzedSocketFactory::ClearSSLSessionCache() {}
235
236 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698