• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 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 <stdint.h>
6 
7 #include <string>
8 #include <tuple>
9 
10 #include <fuzzer/FuzzedDataProvider.h>
11 
12 #include "net/der/input.h"
13 #include "net/der/parse_values.h"
14 #include "net/der/parser.h"
15 #include "net/der/tag.h"
16 #include "third_party/abseil-cpp/absl/types/optional.h"
17 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)18 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
19   FuzzedDataProvider provider(data, size);
20 
21   std::string der = provider.ConsumeRandomLengthString();
22   net::der::Parser parser = net::der::Parser(net::der::Input(&der));
23   while (provider.remaining_bytes()) {
24     switch (provider.ConsumeIntegralInRange<int>(0, 13)) {
25       case 0: {
26         net::der::Tag tag;
27         net::der::Input value;
28         std::ignore = parser.ReadTagAndValue(&tag, &value);
29         break;
30       }
31       case 1: {
32         net::der::Input tlv;
33         std::ignore = parser.ReadRawTLV(&tlv);
34         break;
35       }
36       case 2: {
37         absl::optional<net::der::Input> value;
38         std::ignore = parser.ReadOptionalTag(
39             provider.ConsumeIntegral<net::der::Tag>(), &value);
40         break;
41       }
42       case 3: {
43         bool was_present;
44         std::ignore = parser.SkipOptionalTag(
45             provider.ConsumeIntegral<net::der::Tag>(), &was_present);
46         break;
47       }
48       case 4: {
49         net::der::Input value;
50         std::ignore =
51             parser.ReadTag(provider.ConsumeIntegral<net::der::Tag>(), &value);
52         break;
53       }
54       case 5: {
55         std::ignore = parser.SkipTag(provider.ConsumeIntegral<net::der::Tag>());
56         break;
57       }
58       case 6: {
59         net::der::Parser new_parser;
60         std::ignore = parser.ReadConstructed(
61             provider.ConsumeIntegral<net::der::Tag>(), &new_parser);
62         break;
63       }
64       case 7: {
65         net::der::Parser new_parser;
66         std::ignore = parser.ReadSequence(&new_parser);
67         break;
68       }
69       case 8: {
70         uint8_t value;
71         std::ignore = parser.ReadUint8(&value);
72         break;
73       }
74       case 9: {
75         uint64_t value;
76         std::ignore = parser.ReadUint64(&value);
77         break;
78       }
79       case 10: {
80         std::ignore = parser.ReadBitString();
81         break;
82       }
83       case 11: {
84         net::der::GeneralizedTime generalized_time;
85         std::ignore = parser.ReadGeneralizedTime(&generalized_time);
86         break;
87       }
88       case 12: {
89         net::der::Tag tag;
90         net::der::Input value;
91         std::ignore = parser.PeekTagAndValue(&tag, &value);
92         break;
93       }
94       case 13: {
95         std::ignore = parser.Advance();
96         break;
97       }
98     }
99   }
100 
101   return 0;
102 }
103