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