socks5_client_socket_fuzzer.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #include <stddef.h>
  5. #include <stdint.h>
  6. #include <fuzzer/FuzzedDataProvider.h>
  7. #include <memory>
  8. #include "base/check_op.h"
  9. #include "net/base/address_list.h"
  10. #include "net/base/net_errors.h"
  11. #include "net/base/test_completion_callback.h"
  12. #include "net/log/net_log.h"
  13. #include "net/log/test_net_log.h"
  14. #include "net/socket/fuzzed_socket.h"
  15. #include "net/socket/socks5_client_socket.h"
  16. #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
  17. // Fuzzer for Socks5ClientSocket. Only covers the SOCKS5 greeet and
  18. // handshake.
  19. //
  20. // |data| is used to create a FuzzedSocket to fuzz reads and writes, see that
  21. // class for details.
  22. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  23. // Including an observer; even though the recorded results aren't currently
  24. // used, it'll ensure the netlogging code is fuzzed as well.
  25. net::RecordingNetLogObserver net_log_observer;
  26. FuzzedDataProvider data_provider(data, size);
  27. net::TestCompletionCallback callback;
  28. auto fuzzed_socket =
  29. std::make_unique<net::FuzzedSocket>(&data_provider, net::NetLog::Get());
  30. CHECK_EQ(net::OK, fuzzed_socket->Connect(callback.callback()));
  31. net::SOCKS5ClientSocket socket(std::move(fuzzed_socket),
  32. net::HostPortPair("foo", 80),
  33. TRAFFIC_ANNOTATION_FOR_TESTS);
  34. int result = socket.Connect(callback.callback());
  35. callback.GetResult(result);
  36. return 0;
  37. }