1 // Copyright 2016 The Chromium Authors
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/net_log.h"
18 #include "net/log/test_net_log.h"
19 #include "net/socket/fuzzed_socket.h"
20 #include "net/socket/socks5_client_socket.h"
21 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
22
23 // Fuzzer for Socks5ClientSocket. Only covers the SOCKS5 greeet and
24 // handshake.
25 //
26 // |data| is used to create a FuzzedSocket to fuzz reads and writes, see that
27 // class for details.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)28 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
29 // Including an observer; even though the recorded results aren't currently
30 // used, it'll ensure the netlogging code is fuzzed as well.
31 net::RecordingNetLogObserver net_log_observer;
32
33 FuzzedDataProvider data_provider(data, size);
34
35 net::TestCompletionCallback callback;
36 auto fuzzed_socket =
37 std::make_unique<net::FuzzedSocket>(&data_provider, net::NetLog::Get());
38 CHECK_EQ(net::OK, fuzzed_socket->Connect(callback.callback()));
39
40 net::SOCKS5ClientSocket socket(std::move(fuzzed_socket),
41 net::HostPortPair("foo", 80),
42 TRAFFIC_ANNOTATION_FOR_TESTS);
43 int result = socket.Connect(callback.callback());
44 callback.GetResult(result);
45 return 0;
46 }
47