ntlm_client_fuzzer.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2017 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 <string>
  8. #include <vector>
  9. #include "base/containers/span.h"
  10. #include "net/ntlm/ntlm_client.h"
  11. #include "net/ntlm/ntlm_test_data.h"
  12. std::u16string ConsumeRandomLengthString16(FuzzedDataProvider& data_provider,
  13. size_t max_chars) {
  14. std::string bytes = data_provider.ConsumeRandomLengthString(max_chars * 2);
  15. return std::u16string(reinterpret_cast<const char16_t*>(bytes.data()),
  16. bytes.size() / 2);
  17. }
  18. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  19. FuzzedDataProvider fdp(data, size);
  20. bool is_v2 = fdp.ConsumeBool();
  21. uint64_t client_time = fdp.ConsumeIntegral<uint64_t>();
  22. net::ntlm::NtlmClient client((net::ntlm::NtlmFeatures(is_v2)));
  23. // Generate the input strings and challenge message. The strings will have a
  24. // maximum length 1 character longer than the maximum that |NtlmClient| will
  25. // accept to allow exploring the error cases.
  26. std::u16string domain =
  27. ConsumeRandomLengthString16(fdp, net::ntlm::kMaxFqdnLen + 1);
  28. std::u16string username =
  29. ConsumeRandomLengthString16(fdp, net::ntlm::kMaxUsernameLen + 1);
  30. std::u16string password =
  31. ConsumeRandomLengthString16(fdp, net::ntlm::kMaxPasswordLen + 1);
  32. std::string hostname =
  33. fdp.ConsumeRandomLengthString(net::ntlm::kMaxFqdnLen + 1);
  34. std::string channel_bindings = fdp.ConsumeRandomLengthString(150);
  35. std::string spn =
  36. fdp.ConsumeRandomLengthString(net::ntlm::kMaxFqdnLen + 5 + 1);
  37. std::vector<uint8_t> challenge_msg_bytes =
  38. fdp.ConsumeRemainingBytes<uint8_t>();
  39. client.GenerateAuthenticateMessage(
  40. domain, username, password, hostname, channel_bindings, spn, client_time,
  41. net::ntlm::test::kClientChallenge, base::make_span(challenge_msg_bytes));
  42. return 0;
  43. }