Coverage Report

Created: 2020-05-23 13:54

/src/botan/src/fuzzer/asn1.cpp
Line
Count
Source
1
/*
2
* (C) 2016,2017 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6
7
#include "fuzzers.h"
8
#include <botan/asn1_print.h>
9
#include <fstream>
10
11
class ASN1_Parser final : public Botan::ASN1_Formatter
12
   {
13
   public:
14
2.51k
      ASN1_Parser() : Botan::ASN1_Formatter(true, 64) {}
15
16
   protected:
17
      std::string format(Botan::ASN1_Tag, Botan::ASN1_Tag, size_t, size_t,
18
                         const std::string&) const override
19
36.4k
         {
20
36.4k
         return "";
21
36.4k
         }
22
23
      std::string format_bin(Botan::ASN1_Tag, Botan::ASN1_Tag,
24
                             const std::vector<uint8_t>&) const override
25
11.0k
         {
26
11.0k
         return "";
27
11.0k
         }
28
   };
29
30
void fuzz(const uint8_t in[], size_t len)
31
13.2k
   {
32
13.2k
   try
33
13.2k
      {
34
13.2k
      /*
35
13.2k
      * Here we use an uninitialized ofstream so the fuzzer doesn't spend time
36
13.2k
      * on actual output formatting, no memory is allocated, etc.
37
13.2k
      */
38
13.2k
      std::ofstream out;
39
13.2k
      ASN1_Parser printer;
40
13.2k
      printer.print_to_stream(out, in, len);
41
13.2k
      }
42
13.2k
   catch(Botan::Exception& e) { }
43
13.2k
   }