| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/fuzzed_data_provider.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "net/base/address_list.h" | 12 #include "net/base/address_list.h" |
| 12 #include "net/base/fuzzed_data_provider.h" | |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "net/base/test_completion_callback.h" | 14 #include "net/base/test_completion_callback.h" |
| 15 #include "net/log/test_net_log.h" | 15 #include "net/log/test_net_log.h" |
| 16 #include "net/socket/client_socket_handle.h" | 16 #include "net/socket/client_socket_handle.h" |
| 17 #include "net/socket/fuzzed_socket.h" | 17 #include "net/socket/fuzzed_socket.h" |
| 18 #include "net/socket/socks5_client_socket.h" | 18 #include "net/socket/socks5_client_socket.h" |
| 19 | 19 |
| 20 // Fuzzer for Socks5ClientSocket. Only covers the SOCKS5 greeet and | 20 // Fuzzer for Socks5ClientSocket. Only covers the SOCKS5 greeet and |
| 21 // handshake. | 21 // handshake. |
| 22 // | 22 // |
| 23 // |data| is used to create a FuzzedSocket to fuzz reads and writes, see that | 23 // |data| is used to create a FuzzedSocket to fuzz reads and writes, see that |
| 24 // class for details. | 24 // class for details. |
| 25 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 25 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 26 // Use a test NetLog, to exercise logging code. | 26 // Use a test NetLog, to exercise logging code. |
| 27 net::TestNetLog test_net_log; | 27 net::TestNetLog test_net_log; |
| 28 | 28 |
| 29 net::FuzzedDataProvider data_provider(data, size); | 29 base::FuzzedDataProvider data_provider(data, size); |
| 30 | 30 |
| 31 net::TestCompletionCallback callback; | 31 net::TestCompletionCallback callback; |
| 32 std::unique_ptr<net::FuzzedSocket> fuzzed_socket( | 32 std::unique_ptr<net::FuzzedSocket> fuzzed_socket( |
| 33 new net::FuzzedSocket(&data_provider, &test_net_log)); | 33 new net::FuzzedSocket(&data_provider, &test_net_log)); |
| 34 CHECK_EQ(net::OK, fuzzed_socket->Connect(callback.callback())); | 34 CHECK_EQ(net::OK, fuzzed_socket->Connect(callback.callback())); |
| 35 | 35 |
| 36 std::unique_ptr<net::ClientSocketHandle> socket_handle( | 36 std::unique_ptr<net::ClientSocketHandle> socket_handle( |
| 37 new net::ClientSocketHandle()); | 37 new net::ClientSocketHandle()); |
| 38 socket_handle->SetSocket(std::move(fuzzed_socket)); | 38 socket_handle->SetSocket(std::move(fuzzed_socket)); |
| 39 | 39 |
| 40 net::HostResolver::RequestInfo request_info(net::HostPortPair("foo", 80)); | 40 net::HostResolver::RequestInfo request_info(net::HostPortPair("foo", 80)); |
| 41 net::SOCKS5ClientSocket socket(std::move(socket_handle), request_info); | 41 net::SOCKS5ClientSocket socket(std::move(socket_handle), request_info); |
| 42 int result = socket.Connect(callback.callback()); | 42 int result = socket.Connect(callback.callback()); |
| 43 callback.GetResult(result); | 43 callback.GetResult(result); |
| 44 return 0; | 44 return 0; |
| 45 } | 45 } |
| OLD | NEW |