• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PowerDNS / pdns / 12595591960

03 Jan 2025 09:27AM UTC coverage: 62.774% (+2.5%) from 60.245%
12595591960

Pull #15008

github

web-flow
Merge c2a2749d3 into 788f396a7
Pull Request #15008: Do not follow CNAME records for ANY or CNAME queries

30393 of 78644 branches covered (38.65%)

Branch coverage included in aggregate %.

105822 of 138350 relevant lines covered (76.49%)

4613078.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.38
/pdns/dns.cc
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
#ifdef HAVE_CONFIG_H
23
#include "config.h"
24
#endif
25
#include "dns.hh"
26
#include "misc.hh"
27
#include "views.hh"
28
#include <stdexcept>
29
#include <iostream>
30
#include <boost/algorithm/string.hpp>
31
#include <boost/assign/list_of.hpp>
32
#include "dnsparser.hh"
33

34
const std::array<std::string, 24> RCode::rcodes_s = {
35
  "No Error",
36
  "Form Error",
37
  "Server Failure",
38
  "Non-Existent domain",
39
  "Not Implemented",
40
  "Query Refused",
41
  "Name Exists when it should not",
42
  "RR Set Exists when it should not",
43
  "RR Set that should exist does not",
44
  "Server Not Authoritative for zone / Not Authorized",
45
  "Name not contained in zone",
46
  "Err#11",
47
  "Err#12",
48
  "Err#13",
49
  "Err#14",
50
  "Err#15",  // Last non-extended RCode
51
  "Bad OPT Version / TSIG Signature Failure",
52
  "Key not recognized",
53
  "Signature out of time window",
54
  "Bad TKEY Mode",
55
  "Duplicate key name",
56
  "Algorithm not supported",
57
  "Bad Truncation",
58
  "Bad/missing Server Cookie"
59
};
60

61
static const std::array<std::string, 10> rcodes_short_s =  {
62
  "noerror",
63
  "formerr",
64
  "servfail",
65
  "nxdomain",
66
  "notimp",
67
  "refused",
68
  "yxdomain",
69
  "yxrrset",
70
  "nxrrset",
71
  "notauth",
72
};
73

74
std::string RCode::to_s(uint8_t rcode) {
3,314✔
75
  if (rcode > 0xF) {
3,314!
76
    return std::string("ErrOutOfRange");
×
77
  }
×
78
  return ERCode::to_s(rcode);
3,314✔
79
}
3,314✔
80

81
std::string RCode::to_short_s(uint8_t rcode) {
3,008✔
82
  if (rcode >= rcodes_short_s.size()) {
3,008✔
83
    return "rcode" + std::to_string(rcode);
1,128✔
84
  }
1,128✔
85
  return rcodes_short_s.at(rcode);
1,880✔
86
}
3,008✔
87

88
std::string ERCode::to_s(uint16_t rcode) {
3,314✔
89
  if (rcode >= RCode::rcodes_s.size()) {
3,314!
90
    return std::string("Err#")+std::to_string(rcode);
×
91
  }
×
92
  return RCode::rcodes_s.at(rcode);
3,314✔
93
}
3,314✔
94

95
std::string Opcode::to_s(uint8_t opcode) {
2✔
96
  static const std::array<std::string, 6> s_opcodes = { "Query", "IQuery", "Status", "3", "Notify", "Update" };
2✔
97

98
  if (opcode >= s_opcodes.size()) {
2!
99
    return std::to_string(opcode);
×
100
  }
×
101

102
  return s_opcodes.at(opcode);
2✔
103
}
2✔
104

105
// goal is to hash based purely on the question name, and turn error into 'default'
106
uint32_t hashQuestion(const uint8_t* packet, uint16_t packet_len, uint32_t init, bool& wasOK)
107
{
303,632✔
108
  if (packet_len < sizeof(dnsheader)) {
303,632!
109
    wasOK = false;
×
110
    return init;
×
111
  }
×
112
  // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
113
  pdns::views::UnsignedCharView name(packet + sizeof(dnsheader), packet_len - sizeof(dnsheader));
303,632✔
114
  pdns::views::UnsignedCharView::size_type len = 0;
303,632✔
115

116
  while (len < name.length()) {
914,240✔
117
    uint8_t labellen = name[len++];
914,228✔
118
    if (labellen == 0) {
914,228✔
119
      wasOK = true;
303,620✔
120
      // len is name.length() at max as it was < before the increment
121
      return burtleCI(name.data(), len, init);
303,620✔
122
    }
303,620✔
123
    len += labellen;
610,608✔
124
  }
610,608✔
125
  // We've encountered a label that is too long
126
  wasOK = false;
12✔
127
  return init;
12✔
128
}
303,632✔
129

130
static const std::array<std::string, 4> placeNames = {
131
  "QUESTION",
132
  "ANSWER",
133
  "AUTHORITY",
134
  "ADDITIONAL"
135
};
136

137
std::string DNSResourceRecord::placeString(uint8_t place)
138
{
26✔
139
  if (place >= placeNames.size()) {
26!
140
    return "?";
×
141
  }
×
142
  return placeNames.at(place);
26✔
143
}
26✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc