/src/pdns/pdns/dnsdistdist/fuzz_dnsdistcache.cc
Line | Count | Source (jump to first uncovered line) |
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 "dnsdist-cache.hh" |
24 | | |
25 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); |
26 | | |
27 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) |
28 | 1.21k | { |
29 | | |
30 | 1.21k | if (size > std::numeric_limits<uint16_t>::max()) { |
31 | 6 | return 0; |
32 | 6 | } |
33 | | |
34 | | /* dnsdist's version */ |
35 | | // By default, cookies are not hashed |
36 | 1.20k | DNSDistPacketCache::CacheSettings skipCookieSettings{ |
37 | 1.20k | .d_maxEntries = 10000, |
38 | 1.20k | .d_parseECS = true, |
39 | 1.20k | }; |
40 | 1.20k | DNSDistPacketCache pcSkipCookies(skipCookieSettings); |
41 | | |
42 | | // Do not skip cookies |
43 | 1.20k | DNSDistPacketCache::CacheSettings parseCookieSettings{ |
44 | 1.20k | .d_optionsToSkip = {}, |
45 | 1.20k | .d_maxEntries = 10000, |
46 | 1.20k | .d_parseECS = true, |
47 | | |
48 | 1.20k | }; |
49 | 1.20k | DNSDistPacketCache pcHashCookies(parseCookieSettings); |
50 | | |
51 | 1.20k | try { |
52 | 1.20k | uint16_t qtype; |
53 | 1.20k | uint16_t qclass; |
54 | 1.20k | unsigned int consumed; |
55 | 1.20k | PacketBuffer vect(data, data + size); |
56 | 1.20k | const DNSName qname(reinterpret_cast<const char*>(data), size, sizeof(dnsheader), false, &qtype, &qclass, &consumed); |
57 | 1.20k | pcSkipCookies.getKey(qname.getStorage(), consumed, vect, false); |
58 | 1.20k | pcHashCookies.getKey(qname.getStorage(), consumed, vect, false); |
59 | 1.20k | boost::optional<Netmask> subnet; |
60 | 1.20k | DNSDistPacketCache::getClientSubnet(vect, consumed, subnet); |
61 | 1.20k | } |
62 | 1.20k | catch (const std::exception& e) { |
63 | 220 | } |
64 | 1.20k | catch (const PDNSException& e) { |
65 | 0 | } |
66 | | |
67 | 1.20k | return 0; |
68 | 1.20k | } |