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