Coverage Report

Created: 2026-03-08 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pdns/pdns/fuzz_packetcache.cc
Line
Count
Source
1
/*
2
 * This file is part of PowerDNS or dnsdist.
3
 * Copyright -- PowerDNS.COM B.V. and its contributors
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of version 2 of the GNU General Public License as
7
 * published by the Free Software Foundation.
8
 *
9
 * In addition, for the avoidance of any doubt, permission is granted to
10
 * link this program with OpenSSL and to (re)distribute the binaries
11
 * produced as the result of such linking.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
 */
22
23
#include "packetcache.hh"
24
#include "statbag.hh"
25
26
StatBag S;
27
28
bool g_slogStructured{false};
29
30
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
31
32
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
33
930
{
34
35
930
  if (size > std::numeric_limits<uint16_t>::max() || size < sizeof(dnsheader)) {
36
13
    return 0;
37
13
  }
38
39
917
  std::string input(reinterpret_cast<const char*>(data), size);
40
41
  /* auth's version */
42
917
  try {
43
917
    static const std::unordered_set<uint16_t> optionsToIgnore{EDNSOptionCode::COOKIE};
44
45
917
    PacketCache::canHashPacket(input, optionsToIgnore);
46
917
    DNSName qname(input.data(), input.size(), sizeof(dnsheader), false);
47
917
    PacketCache::queryMatches(input, input, qname, optionsToIgnore);
48
917
  }
49
917
  catch (const std::exception& e) {
50
287
  }
51
917
  catch (const PDNSException& e) {
52
0
  }
53
54
  /* recursor's version */
55
917
  try {
56
917
    static const std::unordered_set<uint16_t> optionsToIgnore{EDNSOptionCode::COOKIE, EDNSOptionCode::ECS};
57
58
917
    PacketCache::canHashPacket(input, optionsToIgnore);
59
917
    DNSName qname(input.data(), input.size(), sizeof(dnsheader), false);
60
917
    PacketCache::queryMatches(input, input, qname, optionsToIgnore);
61
917
  }
62
917
  catch (const std::exception& e) {
63
287
  }
64
917
  catch (const PDNSException& e) {
65
0
  }
66
67
917
  return 0;
68
917
}