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/socks_client_socket.h" | |
6 | |
7 #include <stddef.h> | 5 #include <stddef.h> |
8 #include <stdint.h> | 6 #include <stdint.h> |
9 | 7 |
| 8 #include <memory> |
| 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
13 #include "net/base/address_list.h" | 12 #include "net/base/address_list.h" |
14 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
15 #include "net/base/test_completion_callback.h" | 14 #include "net/base/test_completion_callback.h" |
16 #include "net/dns/host_resolver.h" | 15 #include "net/dns/host_resolver.h" |
17 #include "net/dns/mock_host_resolver.h" | 16 #include "net/dns/mock_host_resolver.h" |
18 #include "net/log/test_net_log.h" | 17 #include "net/log/test_net_log.h" |
19 #include "net/socket/client_socket_handle.h" | 18 #include "net/socket/client_socket_handle.h" |
20 #include "net/socket/fuzzed_socket.h" | 19 #include "net/socket/fuzzed_socket.h" |
| 20 #include "net/socket/socks_client_socket.h" |
21 | 21 |
22 // Fuzzer for SocksClientSocket. Only covers the SOCKS4 handshake. | 22 // Fuzzer for SocksClientSocket. Only covers the SOCKS4 handshake. |
23 // | 23 // |
24 // |data| is used to create a FuzzedSocket to fuzz reads and writes, see that | 24 // |data| is used to create a FuzzedSocket to fuzz reads and writes, see that |
25 // class for details. | 25 // class for details. |
26 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 26 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
27 // Needed for thread checks and waits. | 27 // Needed for thread checks and waits. |
28 base::MessageLoopForIO message_loop; | 28 base::MessageLoopForIO message_loop; |
29 | 29 |
30 // Use a test NetLog, to exercise logging code. | 30 // Use a test NetLog, to exercise logging code. |
(...skipping 18 matching lines...) Expand all Loading... |
49 case 1: | 49 case 1: |
50 rules->AddRule("*", "::1"); | 50 rules->AddRule("*", "::1"); |
51 break; | 51 break; |
52 case 2: | 52 case 2: |
53 rules->AddSimulatedFailure("*"); | 53 rules->AddSimulatedFailure("*"); |
54 break; | 54 break; |
55 } | 55 } |
56 mock_host_resolver.set_rules(rules.get()); | 56 mock_host_resolver.set_rules(rules.get()); |
57 | 57 |
58 net::TestCompletionCallback callback; | 58 net::TestCompletionCallback callback; |
59 scoped_ptr<net::FuzzedSocket> fuzzed_socket( | 59 std::unique_ptr<net::FuzzedSocket> fuzzed_socket( |
60 new net::FuzzedSocket(data, size, bound_test_net_log.bound())); | 60 new net::FuzzedSocket(data, size, bound_test_net_log.bound())); |
61 CHECK_EQ(net::OK, fuzzed_socket->Connect(callback.callback())); | 61 CHECK_EQ(net::OK, fuzzed_socket->Connect(callback.callback())); |
62 | 62 |
63 scoped_ptr<net::ClientSocketHandle> socket_handle( | 63 std::unique_ptr<net::ClientSocketHandle> socket_handle( |
64 new net::ClientSocketHandle()); | 64 new net::ClientSocketHandle()); |
65 socket_handle->SetSocket(std::move(fuzzed_socket)); | 65 socket_handle->SetSocket(std::move(fuzzed_socket)); |
66 | 66 |
67 net::HostResolver::RequestInfo request_info(net::HostPortPair("foo", 80)); | 67 net::HostResolver::RequestInfo request_info(net::HostPortPair("foo", 80)); |
68 net::SOCKSClientSocket socket(std::move(socket_handle), request_info, | 68 net::SOCKSClientSocket socket(std::move(socket_handle), request_info, |
69 net::DEFAULT_PRIORITY, &mock_host_resolver); | 69 net::DEFAULT_PRIORITY, &mock_host_resolver); |
70 int result = socket.Connect(callback.callback()); | 70 int result = socket.Connect(callback.callback()); |
71 callback.GetResult(result); | 71 callback.GetResult(result); |
72 return 0; | 72 return 0; |
73 } | 73 } |
OLD | NEW |