xref: /aosp_15_r20/external/cronet/net/cert/crl_set_fuzzer.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2019 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 "net/cert/crl_set.h"
11 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)12 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
13   if (size < 32 + 32 + 20)
14     return 0;
15 
16   FuzzedDataProvider data_provider(data, size);
17   std::string spki_hash = data_provider.ConsumeBytesAsString(32);
18   std::string issuer_hash = data_provider.ConsumeBytesAsString(32);
19   size_t serial_length = data_provider.ConsumeIntegralInRange(4, 19);
20   std::string serial = data_provider.ConsumeBytesAsString(serial_length);
21   std::string crlset_data = data_provider.ConsumeRemainingBytesAsString();
22 
23   scoped_refptr<net::CRLSet> out_crl_set;
24   net::CRLSet::Parse(crlset_data, &out_crl_set);
25 
26   if (out_crl_set) {
27     out_crl_set->CheckSPKI(spki_hash);
28     out_crl_set->CheckSerial(serial, issuer_hash);
29     out_crl_set->IsExpired();
30   }
31 
32   return 0;
33 }
34