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/socket/fuzzed_socket_factory.h" | 5 #include "net/socket/fuzzed_socket_factory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/test/fuzzed_data_provider.h" | 9 #include "base/test/fuzzed_data_provider.h" |
10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
11 #include "net/base/ip_endpoint.h" | 11 #include "net/base/ip_endpoint.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 #include "net/base/network_change_notifier.h" | 13 #include "net/base/network_change_notifier.h" |
14 #include "net/log/net_log.h" | 14 #include "net/log/net_log_with_source.h" |
15 #include "net/socket/client_socket_handle.h" | 15 #include "net/socket/client_socket_handle.h" |
16 #include "net/socket/connection_attempts.h" | 16 #include "net/socket/connection_attempts.h" |
17 #include "net/socket/fuzzed_socket.h" | 17 #include "net/socket/fuzzed_socket.h" |
18 #include "net/socket/ssl_client_socket.h" | 18 #include "net/socket/ssl_client_socket.h" |
19 #include "net/udp/fuzzed_datagram_client_socket.h" | 19 #include "net/udp/fuzzed_datagram_client_socket.h" |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 | 22 |
| 23 class NetLog; |
| 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 // SSLClientSocket implementation that always fails to connect. | 27 // SSLClientSocket implementation that always fails to connect. |
26 class FailingSSLClientSocket : public SSLClientSocket { | 28 class FailingSSLClientSocket : public SSLClientSocket { |
27 public: | 29 public: |
28 FailingSSLClientSocket() {} | 30 FailingSSLClientSocket() {} |
29 ~FailingSSLClientSocket() override {} | 31 ~FailingSSLClientSocket() override {} |
30 | 32 |
31 // Socket implementation: | 33 // Socket implementation: |
32 int Read(IOBuffer* buf, | 34 int Read(IOBuffer* buf, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 base::FuzzedDataProvider* data_provider) | 131 base::FuzzedDataProvider* data_provider) |
130 : data_provider_(data_provider) {} | 132 : data_provider_(data_provider) {} |
131 | 133 |
132 FuzzedSocketFactory::~FuzzedSocketFactory() {} | 134 FuzzedSocketFactory::~FuzzedSocketFactory() {} |
133 | 135 |
134 std::unique_ptr<DatagramClientSocket> | 136 std::unique_ptr<DatagramClientSocket> |
135 FuzzedSocketFactory::CreateDatagramClientSocket( | 137 FuzzedSocketFactory::CreateDatagramClientSocket( |
136 DatagramSocket::BindType bind_type, | 138 DatagramSocket::BindType bind_type, |
137 const RandIntCallback& rand_int_cb, | 139 const RandIntCallback& rand_int_cb, |
138 NetLog* net_log, | 140 NetLog* net_log, |
139 const NetLog::Source& source) { | 141 const NetLogSource& source) { |
140 return base::MakeUnique<FuzzedDatagramClientSocket>(data_provider_); | 142 return base::MakeUnique<FuzzedDatagramClientSocket>(data_provider_); |
141 } | 143 } |
142 | 144 |
143 std::unique_ptr<StreamSocket> FuzzedSocketFactory::CreateTransportClientSocket( | 145 std::unique_ptr<StreamSocket> FuzzedSocketFactory::CreateTransportClientSocket( |
144 const AddressList& addresses, | 146 const AddressList& addresses, |
145 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, | 147 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
146 NetLog* net_log, | 148 NetLog* net_log, |
147 const NetLog::Source& source) { | 149 const NetLogSource& source) { |
148 std::unique_ptr<FuzzedSocket> socket( | 150 std::unique_ptr<FuzzedSocket> socket( |
149 new FuzzedSocket(data_provider_, net_log)); | 151 new FuzzedSocket(data_provider_, net_log)); |
150 socket->set_fuzz_connect_result(true); | 152 socket->set_fuzz_connect_result(true); |
151 // Just use the first address. | 153 // Just use the first address. |
152 socket->set_remote_address(*addresses.begin()); | 154 socket->set_remote_address(*addresses.begin()); |
153 return std::move(socket); | 155 return std::move(socket); |
154 } | 156 } |
155 | 157 |
156 std::unique_ptr<SSLClientSocket> FuzzedSocketFactory::CreateSSLClientSocket( | 158 std::unique_ptr<SSLClientSocket> FuzzedSocketFactory::CreateSSLClientSocket( |
157 std::unique_ptr<ClientSocketHandle> transport_socket, | 159 std::unique_ptr<ClientSocketHandle> transport_socket, |
158 const HostPortPair& host_and_port, | 160 const HostPortPair& host_and_port, |
159 const SSLConfig& ssl_config, | 161 const SSLConfig& ssl_config, |
160 const SSLClientSocketContext& context) { | 162 const SSLClientSocketContext& context) { |
161 return base::MakeUnique<FailingSSLClientSocket>(); | 163 return base::MakeUnique<FailingSSLClientSocket>(); |
162 } | 164 } |
163 | 165 |
164 void FuzzedSocketFactory::ClearSSLSessionCache() {} | 166 void FuzzedSocketFactory::ClearSSLSessionCache() {} |
165 | 167 |
166 } // namespace net | 168 } // namespace net |
OLD | NEW |