From 31b47b5c573c78ca40b6aa84d9dbb6cd8ecdb41a Mon Sep 17 00:00:00 2001 From: Razvan Becheriu Date: Fri, 8 Mar 2024 20:19:05 +0200 Subject: [PATCH] [#3208] clean up code --- src/lib/dns/char_string.cc | 11 +- src/lib/dns/labelsequence.cc | 2 +- src/lib/dns/master_lexer.cc | 17 ++- src/lib/dns/master_lexer.h | 2 +- src/lib/dns/master_lexer_inputsource.cc | 6 +- src/lib/dns/master_loader.cc | 9 +- src/lib/dns/message.h | 2 +- src/lib/dns/messagerenderer.cc | 3 +- src/lib/dns/rdata.cc | 3 +- src/lib/dns/rdataclass.cc | 3 +- src/lib/dns/rrclass.h | 8 +- src/lib/dns/rrparamregistry.cc | 7 +- src/lib/dns/rrset.cc | 9 +- src/lib/dns/rrttl.cc | 3 +- src/lib/dns/rrtype.h | 9 +- src/lib/dns/tests/message_unittest.cc | 6 +- .../dns/tests/rdata_char_string_unittest.cc | 2 +- src/lib/dns/tests/rdata_opt_unittest.cc | 4 +- src/lib/dns/tests/rdata_soa_unittest.cc | 2 +- src/lib/dns/tests/rdata_txt_like_unittest.cc | 2 +- src/lib/dns/tests/rdata_unittest.h | 2 +- src/lib/dns/tests/rrclass_unittest.cc | 4 +- src/lib/dns/tests/rrtype_unittest.cc | 101 ++++++++++++++++-- src/lib/dns/tests/tsig_unittest.cc | 10 +- src/lib/dns/tsig.cc | 5 +- 25 files changed, 158 insertions(+), 74 deletions(-) diff --git a/src/lib/dns/char_string.cc b/src/lib/dns/char_string.cc index c28d2047c5..25cb1f180f 100644 --- a/src/lib/dns/char_string.cc +++ b/src/lib/dns/char_string.cc @@ -16,7 +16,6 @@ #include -#include #include #include #include @@ -66,7 +65,10 @@ stringToCharString(const MasterToken::StringRegion& str_region, int c = (*s & 0xff); if (escape && std::isdigit(c) != 0) { c = decimalToNumber(s, s_end); - assert(n >= 3); + // decimalToNumber() already throws if (s_end - s) is less + // than 3. 'n' is an unsigned type (size_t) and can underflow. + // 'n' and 's' are also updated by 1 in the for statement's + // expression, so we update them by 2 instead of 3 here. n -= 2; s += 2; } else if (!escape && c == '\\') { @@ -98,10 +100,7 @@ stringToCharStringData(const MasterToken::StringRegion& str_region, if (escape && std::isdigit(c) != 0) { c = decimalToNumber(s, s_end); // decimalToNumber() already throws if (s_end - s) is less - // than 3, so the following assertion is unnecessary. But we - // assert it anyway. 'n' is an unsigned type (size_t) and - // can underflow. - assert(n >= 3); + // than 3. 'n' is an unsigned type (size_t) and can underflow. // 'n' and 's' are also updated by 1 in the for statement's // expression, so we update them by 2 instead of 3 here. n -= 2; diff --git a/src/lib/dns/labelsequence.cc b/src/lib/dns/labelsequence.cc index 04f3bc2fe3..33cc3ef04d 100644 --- a/src/lib/dns/labelsequence.cc +++ b/src/lib/dns/labelsequence.cc @@ -24,7 +24,7 @@ LabelSequence::LabelSequence(const void* buf) { // will lead to a crash, so disabling this check is not // unsafe. Except for a programming mistake, this case should not // happen. - if (buf == NULL) { + if (!buf) { isc_throw(BadValue, "Null pointer passed to LabelSequence constructor"); } diff --git a/src/lib/dns/master_lexer.cc b/src/lib/dns/master_lexer.cc index d157aa0d10..2b521e3ab1 100644 --- a/src/lib/dns/master_lexer.cc +++ b/src/lib/dns/master_lexer.cc @@ -7,7 +7,7 @@ #include #include - +#include #include #include #include @@ -15,7 +15,6 @@ #include #include -#include #include #include #include @@ -84,7 +83,7 @@ struct MasterLexer::MasterLexerImpl { } void setTotalSize() { - assert(source_ != NULL); + isc_throw_assert(source_); if (total_size_ != SOURCE_SIZE_UNKNOWN) { const size_t current_size = source_->getSize(); if (current_size != SOURCE_SIZE_UNKNOWN) { @@ -236,8 +235,8 @@ MasterLexer::getNextToken(Options options) { } // Make sure a token was produced. Since this Can Not Happen, we assert // here instead of throwing. - assert(impl_->token_.getType() != MasterToken::ERROR || - impl_->token_.getErrorCode() != MasterToken::NO_TOKEN_PRODUCED); + isc_throw_assert(impl_->token_.getType() != MasterToken::ERROR || + impl_->token_.getErrorCode() != MasterToken::NO_TOKEN_PRODUCED); return (impl_->token_); } @@ -287,7 +286,7 @@ MasterLexer::getNextToken(MasterToken::Type expect, bool eol_ok) { throw LexerError(__FILE__, __LINE__, MasterToken(MasterToken::UNEXPECTED_END)); } - assert(expect == MasterToken::NUMBER); + isc_throw_assert(expect == MasterToken::NUMBER); throw LexerError(__FILE__, __LINE__, MasterToken(MasterToken::BAD_NUMBER)); } @@ -329,7 +328,7 @@ MasterToken::getErrorText() const { } // The class integrity ensures the following: - assert(val_.error_code_ < error_text_max_count); + isc_throw_assert(val_.error_code_ < error_text_max_count); return (error_text[val_.error_code_]); } @@ -426,7 +425,7 @@ State::getInstance(ID state_id) { // This is a bug of the caller, and this method is only expected to be // used by tests, so we just forcefully make it fail by asserting the // condition. - assert(false); + isc_throw_assert(false); return (STRING_STATE); // a dummy return, to silence some compilers. } @@ -540,7 +539,7 @@ QString::handle(MasterLexer& lexer) const { } else if (c == '"') { if (escaped) { // found escaped '"'. overwrite the preceding backslash. - assert(!data.empty()); + isc_throw_assert(!data.empty()); escaped = false; data.back() = '"'; } else { diff --git a/src/lib/dns/master_lexer.h b/src/lib/dns/master_lexer.h index 0965aa1c1f..ddd2da50cc 100644 --- a/src/lib/dns/master_lexer.h +++ b/src/lib/dns/master_lexer.h @@ -384,7 +384,7 @@ public: /// case of failure. /// /// \return true if pushing the file succeeds; false otherwise. - bool pushSource(const char* filename, std::string* error = NULL); + bool pushSource(const char* filename, std::string* error = 0); /// \brief Make the given stream the current input source of MasterLexer. /// diff --git a/src/lib/dns/master_lexer_inputsource.cc b/src/lib/dns/master_lexer_inputsource.cc index 1a1058fdfe..ef8b078ef6 100644 --- a/src/lib/dns/master_lexer_inputsource.cc +++ b/src/lib/dns/master_lexer_inputsource.cc @@ -6,12 +6,12 @@ #include +#include #include #include #include #include -#include #include #include @@ -72,7 +72,7 @@ getStreamSize(std::istream& is) { isc_throw(InputSource::OpenError, "failed to seek beginning of input source"); } - assert(len >= 0 || ret == MasterLexer::SOURCE_SIZE_UNKNOWN); + isc_throw_assert(len >= 0 || ret == MasterLexer::SOURCE_SIZE_UNKNOWN); return (ret); } @@ -186,7 +186,7 @@ InputSource::ungetChar() { void InputSource::ungetAll() { - assert(total_pos_ >= buffer_pos_); + isc_throw_assert(total_pos_ >= buffer_pos_); total_pos_ -= buffer_pos_; buffer_pos_ = 0; line_ = saved_line_; diff --git a/src/lib/dns/master_loader.cc b/src/lib/dns/master_loader.cc index 1c48388a6e..3c756e9afb 100644 --- a/src/lib/dns/master_loader.cc +++ b/src/lib/dns/master_loader.cc @@ -6,6 +6,7 @@ #include +#include #include #include #include @@ -190,7 +191,7 @@ private: // We move in tandem, there's an extra item included during the // initialization, so we can never run out of them - assert(!include_info_.empty()); + isc_throw_assert(!include_info_.empty()); const IncludeInfo& info(include_info_.back()); active_origin_ = info.first; last_name_ = info.second; @@ -259,7 +260,7 @@ private: } else { // If it is not optional, we must not get anything but // a string token. - assert(is_optional); + isc_throw_assert(is_optional); // We return the newline there. This is because we want to // behave the same if there is or isn't the name, leaving the @@ -443,7 +444,7 @@ private: "last explicitly stated TTL"); warn_rfc1035_ttl_ = false; // we only warn about this once } - assert(current_ttl_); + isc_throw_assert(current_ttl_); return (*current_ttl_); } @@ -961,7 +962,7 @@ MasterLoader::MasterLoaderImpl::loadIncremental(size_t count_limit) { } // We are going to parse an RR, have known the owner name, // and are now seeing the next string token in the rest of the RR. - assert(next_token.getType() == MasterToken::STRING); + isc_throw_assert(next_token.getType() == MasterToken::STRING); bool explicit_ttl = false; const RRType rrtype = parseRRParams(explicit_ttl, next_token); diff --git a/src/lib/dns/message.h b/src/lib/dns/message.h index 2a4ecf579a..5bd9e00ebe 100644 --- a/src/lib/dns/message.h +++ b/src/lib/dns/message.h @@ -583,7 +583,7 @@ public: /// \param tsig_ctx A TSIG context that is to be used for signing the /// message void toWire(AbstractMessageRenderer& renderer, - TSIGContext* tsig_ctx = NULL); + TSIGContext* tsig_ctx = 0); /// Parse options. /// diff --git a/src/lib/dns/messagerenderer.cc b/src/lib/dns/messagerenderer.cc index bc59e16d63..684c446849 100644 --- a/src/lib/dns/messagerenderer.cc +++ b/src/lib/dns/messagerenderer.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -126,7 +127,7 @@ private: // on a valid name, which is an assumption for this class. // But we'll abort if a bug could cause an infinite loop. i += 2; - assert(i < Name::MAX_WIRE); + isc_throw_assert(i < Name::MAX_WIRE); } llen = buffer[pos]; } else { diff --git a/src/lib/dns/rdata.cc b/src/lib/dns/rdata.cc index df48785364..6546c5d754 100644 --- a/src/lib/dns/rdata.cc +++ b/src/lib/dns/rdata.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -165,7 +166,7 @@ createRdata(const RRType& rrtype, const RRClass& rrclass, } while (true); // We shouldn't reach here - assert(false); + isc_throw_assert(false); return (RdataPtr()); // add explicit return to silence some compilers } diff --git a/src/lib/dns/rdataclass.cc b/src/lib/dns/rdataclass.cc index adc4e98881..39df1bcc1f 100644 --- a/src/lib/dns/rdataclass.cc +++ b/src/lib/dns/rdataclass.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -1318,7 +1319,7 @@ SOA::SOA(const Name& mname, const Name& rname, uint32_t serial, b.writeUint32(retry); b.writeUint32(expire); b.writeUint32(minimum); - assert(b.getLength() == sizeof(numdata_)); + isc_throw_assert(b.getLength() == sizeof(numdata_)); memcpy(numdata_, b.getData(), sizeof(numdata_)); } diff --git a/src/lib/dns/rrclass.h b/src/lib/dns/rrclass.h index 12d94f2ef3..7ac7f3491a 100644 --- a/src/lib/dns/rrclass.h +++ b/src/lib/dns/rrclass.h @@ -97,7 +97,8 @@ public: /// This constructor never throws an exception. /// /// \param classcode An 16-bit integer code corresponding to the RRClass. - explicit RRClass(uint16_t classcode) : classcode_(classcode) {} + explicit RRClass(uint16_t classcode) : classcode_(classcode) { + } /// /// A valid string is one of "well-known" textual class representations /// such as "IN" or "CH", or in the standard format for "unknown" @@ -285,18 +286,15 @@ public: return (classcode_ < other.classcode_); } - // BEGIN_WELL_KNOWN_CLASS_DECLARATIONS static const RRClass& ANY(); static const RRClass& IN(); static const RRClass& CH(); static const RRClass& NONE(); - // END_WELL_KNOWN_CLASS_DECLARATIONS private: uint16_t classcode_; }; -// BEGIN_WELL_KNOWN_CLASS_DEFINITIONS inline const RRClass& RRClass::ANY() { static RRClass rrclass(255); @@ -321,8 +319,6 @@ RRClass::NONE() { return (rrclass); } -// END_WELL_KNOWN_CLASS_DEFINITIONS - /// /// \brief Insert the \c RRClass as a string into stream. /// diff --git a/src/lib/dns/rrparamregistry.cc b/src/lib/dns/rrparamregistry.cc index f047188e9f..2a485306a8 100644 --- a/src/lib/dns/rrparamregistry.cc +++ b/src/lib/dns/rrparamregistry.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -194,7 +195,6 @@ RRParamRegistry::RRParamRegistry() : impl_(new RRParamRegistryImpl()) { // set up parameters for well-known RRs try { - // BEGIN_WELL_KNOWN_PARAMS add("A", 1, "IN", 1, RdataFactoryPtr(new RdataFactory())); add("NS", 2, "IN", 1, RdataFactoryPtr(new RdataFactory())); add("SOA", 6, "IN", 1, RdataFactoryPtr(new RdataFactory())); @@ -300,7 +300,6 @@ RRParamRegistry::RRParamRegistry() : impl_(new RRParamRegistryImpl()) { // Meta classes addClass("CH", 3); addClass("NONE", 254); - // END_WELL_KNOWN_PARAMS } catch (...) { throw; } @@ -403,7 +402,7 @@ bool CICharEqual(char c1, char c2) { bool caseStringEqual(const string& s1, const string& s2, size_t n) { - assert(s1.size() >= n && s2.size() >= n); + isc_throw_assert(s1.size() >= n && s2.size() >= n); return (mismatch(s1.begin(), s1.begin() + n, s2.begin(), CICharEqual).first == s1.begin() + n); @@ -457,7 +456,7 @@ removeParam(uint16_t code, MC& codemap, MS& stringmap) { if (found != codemap.end()) { size_t erased = stringmap.erase(found->second->code_string_); // We must have a corresponding entry of the str2 map exists - assert(erased == 1); + isc_throw_assert(erased == 1); codemap.erase(found); diff --git a/src/lib/dns/rrset.cc b/src/lib/dns/rrset.cc index 1ab3bde031..1360c1255d 100644 --- a/src/lib/dns/rrset.cc +++ b/src/lib/dns/rrset.cc @@ -6,6 +6,7 @@ #include +#include #include #include #include @@ -97,7 +98,7 @@ rrsetToWire(const AbstractRRset& rrset, T& output, const size_t limit) { // other options. Details to be considered. do { const size_t pos0 = output.getLength(); - assert(pos0 < 65536); + isc_throw_assert(pos0 < 65536); rrset.getName().toWire(output); rrset.getType().toWire(output); @@ -203,7 +204,7 @@ BasicRRsetImpl::toWire(AbstractMessageRenderer& renderer, size_t limit) const { // other options. Details to be considered. for (auto const& rdata : rdatalist_) { const size_t pos0 = renderer.getLength(); - assert(pos0 < 65536); + isc_throw_assert(pos0 < 65536); name_.toWire(renderer); rrtype_.toWire(renderer); @@ -320,7 +321,7 @@ BasicRRset::getLength() const { rrlen += 2; // RDLENGTH field rrlen += it->getCurrent().getLength(); - assert(length + rrlen < 65536); + isc_throw_assert(length + rrlen < 65536); length += rrlen; it->next(); @@ -369,7 +370,7 @@ RRset::getLength() const { const uint16_t rrsigs_length = rrsig_->getLength(); // the uint16_ts are promoted to ints during addition below, so // it won't overflow a 16-bit register. - assert(length + rrsigs_length < 65536); + isc_throw_assert(length + rrsigs_length < 65536); length += rrsigs_length; } diff --git a/src/lib/dns/rrttl.cc b/src/lib/dns/rrttl.cc index 8d9a7112d0..3b543293dd 100644 --- a/src/lib/dns/rrttl.cc +++ b/src/lib/dns/rrttl.cc @@ -6,6 +6,7 @@ #include +#include #include #include #include @@ -127,7 +128,7 @@ parseTTLString(const string& ttlstr, uint32_t& ttlval, string* error_txt) { // seconds cannot be out of range at this point. const uint64_t seconds = value * multiply; - assert(seconds <= 0xffffffff); + isc_throw_assert(seconds <= 0xffffffff); // Add what we found val += seconds; diff --git a/src/lib/dns/rrtype.h b/src/lib/dns/rrtype.h index 63d8e5282e..ae575d0614 100644 --- a/src/lib/dns/rrtype.h +++ b/src/lib/dns/rrtype.h @@ -104,7 +104,8 @@ public: /// This constructor never throws an exception. /// /// \param typecode An 16-bit integer code corresponding to the RRType. - explicit RRType(uint16_t typecode) : typecode_(typecode) {} + explicit RRType(uint16_t typecode) : typecode_(typecode) { + } /// Constructor from a string. /// /// A valid string is one of "well-known" textual type representations @@ -257,7 +258,6 @@ public: } //@} - // BEGIN_WELL_KNOWN_TYPE_DECLARATIONS static const RRType& A(); static const RRType& NS(); static const RRType& SOA(); @@ -270,14 +270,11 @@ public: static const RRType& TKEY(); static const RRType& TSIG(); static const RRType& ANY(); - // END_WELL_KNOWN_TYPE_DECLARATIONS private: uint16_t typecode_; }; -// BEGIN_WELL_KNOWN_TYPE_DEFINITIONS - inline const RRType& RRType::A() { static RRType rrtype(1); @@ -350,8 +347,6 @@ RRType::ANY() { return (rrtype); } -// END_WELL_KNOWN_TYPE_DEFINITIONS - /// /// \brief Insert the \c RRType as a string into stream. /// diff --git a/src/lib/dns/tests/message_unittest.cc b/src/lib/dns/tests/message_unittest.cc index 850d018158..db5fcd6dec 100644 --- a/src/lib/dns/tests/message_unittest.cc +++ b/src/lib/dns/tests/message_unittest.cc @@ -859,7 +859,7 @@ commonTSIGToWireCheck(Message& message, MessageRenderer& renderer, TSIGContext& tsig_ctx, const char* const expected_file, unsigned int message_flags = RD_FLAG, RRType qtype = RRType::A(), - const vector* answer_data = NULL) { + const vector* answer_data = 0) { message.setOpcode(Opcode::QUERY()); message.setRcode(Rcode::NOERROR()); if ((message_flags & QR_FLAG) != 0) { @@ -874,7 +874,7 @@ commonTSIGToWireCheck(Message& message, MessageRenderer& renderer, message.addQuestion(Question(Name("www.example.com"), RRClass::IN(), qtype)); - if (answer_data != NULL) { + if (answer_data) { RRsetPtr ans_rrset(new RRset(Name("www.example.com"), RRClass::IN(), qtype, RRTTL(86400))); for (auto const& it : *answer_data) { @@ -1026,7 +1026,7 @@ TEST_F(MessageTest, toWireTSIGTruncation3) { EXPECT_TRUE(message_parse.getHeaderFlag(Message::HEADERFLAG_TC)); // Note that the number of questions are 66, not 67 as we tried to add. EXPECT_EQ(66, message_parse.getRRCount(Message::SECTION_QUESTION)); - EXPECT_TRUE(message_parse.getTSIGRecord() != NULL); + EXPECT_TRUE(message_parse.getTSIGRecord()); } TEST_F(MessageTest, toWireTSIGNoTruncation) { diff --git a/src/lib/dns/tests/rdata_char_string_unittest.cc b/src/lib/dns/tests/rdata_char_string_unittest.cc index 607e6afe6b..fb6de53d42 100644 --- a/src/lib/dns/tests/rdata_char_string_unittest.cc +++ b/src/lib/dns/tests/rdata_char_string_unittest.cc @@ -161,7 +161,7 @@ TEST_F(CharStringTest, charStringToString) { uint8_t idata[32]; size_t length = std::strlen(cur->data); // length (1 byte) + string (length bytes) - assert(sizeof(idata) > length); + ASSERT_TRUE(sizeof(idata) > length); idata[0] = static_cast(length); std::memcpy(idata + 1, cur->data, length); const CharString test_data(idata, idata + length + 1); diff --git a/src/lib/dns/tests/rdata_opt_unittest.cc b/src/lib/dns/tests/rdata_opt_unittest.cc index 6be2d08a39..a235183529 100644 --- a/src/lib/dns/tests/rdata_opt_unittest.cc +++ b/src/lib/dns/tests/rdata_opt_unittest.cc @@ -50,7 +50,7 @@ TEST_F(Rdata_OPT_Test, createFromWire) { // we can only check these don't throw. EXPECT_NO_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass("CLASS4096"), "rdata_opt_fromWire1")); - EXPECT_NO_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass::ANY(), + EXPECT_NO_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass::CH(), "rdata_opt_fromWire1", 2)); // Short RDLEN. This throws InvalidRdataLength even if subsequent @@ -119,7 +119,7 @@ TEST_F(Rdata_OPT_Test, compare) { const generic::OPT rdata_opt; EXPECT_THROW(rdata_opt.compare( - *rdataFactoryFromFile(RRType::OPT(), RRClass::ANY(), + *rdataFactoryFromFile(RRType::OPT(), RRClass::CH(), "rdata_opt_fromWire1", 2)), isc::InvalidOperation); diff --git a/src/lib/dns/tests/rdata_soa_unittest.cc b/src/lib/dns/tests/rdata_soa_unittest.cc index 21f4dc4854..f0da2436e7 100644 --- a/src/lib/dns/tests/rdata_soa_unittest.cc +++ b/src/lib/dns/tests/rdata_soa_unittest.cc @@ -36,7 +36,7 @@ protected: {} template - void checkFromTextSOA(const string& soa_txt, const Name* origin = NULL, + void checkFromTextSOA(const string& soa_txt, const Name* origin = 0, bool throw_str_version = true, bool throw_lexer_version = true) { diff --git a/src/lib/dns/tests/rdata_txt_like_unittest.cc b/src/lib/dns/tests/rdata_txt_like_unittest.cc index dcb5ac168b..35cbf90f21 100644 --- a/src/lib/dns/tests/rdata_txt_like_unittest.cc +++ b/src/lib/dns/tests/rdata_txt_like_unittest.cc @@ -240,7 +240,7 @@ makeLargest(vector& data) { data.push_back(254); data.insert(data.end(), 254, ch); - assert(data.size() == 65535); + ASSERT_TRUE(data.size() == 65535); } TYPED_TEST(Rdata_TXT_LIKE_Test, createFromWire) { diff --git a/src/lib/dns/tests/rdata_unittest.h b/src/lib/dns/tests/rdata_unittest.h index c412bbbc06..74bd5c4652 100644 --- a/src/lib/dns/tests/rdata_unittest.h +++ b/src/lib/dns/tests/rdata_unittest.h @@ -45,7 +45,7 @@ protected: const RdataType& rdata_expected, bool throw_str_version = true, bool throw_lexer_version = true, - const Name* origin = NULL) { + const Name* origin = 0) { SCOPED_TRACE(rdata_txt); if (throw_str_version) { diff --git a/src/lib/dns/tests/rrclass_unittest.cc b/src/lib/dns/tests/rrclass_unittest.cc index 54e616cd77..c5fb01eab0 100644 --- a/src/lib/dns/tests/rrclass_unittest.cc +++ b/src/lib/dns/tests/rrclass_unittest.cc @@ -153,8 +153,8 @@ TEST_F(RRClassTest, LeftShiftOperator) { // http://www.iana.org/assignments/dns-parameters/dns-parameters.xml struct ClassParam { const char* const txt; // "IN", "CH", etc - const uint16_t code; // 1, 3, - const RRClass& (*obj)(); // RRClass::IN(), etc + const uint16_t code; // 1, 3, etc + const RRClass& (*obj)(); // RRClass::IN(), RRClass::CH(), etc } known_classes[] = { {"IN", 1, RRClass::IN}, {"CH", 3, RRClass::CH}, {"NONE", 254, RRClass::NONE}, {"ANY", 255, RRClass::ANY}, diff --git a/src/lib/dns/tests/rrtype_unittest.cc b/src/lib/dns/tests/rrtype_unittest.cc index 97975409b8..d80e4a3fe2 100644 --- a/src/lib/dns/tests/rrtype_unittest.cc +++ b/src/lib/dns/tests/rrtype_unittest.cc @@ -149,12 +149,101 @@ struct TypeParam { const uint16_t code; // 1, 28, 2, etc const RRType& (*obj)(); // RRType::A(), etc } known_types[] = { - {"A", 1, RRType::A}, {"NS", 2, RRType::NS}, - {"SOA", 6, RRType::SOA}, {"PTR", 12, RRType::PTR}, - {"TXT", 16, RRType::TXT}, {"AAAA", 28, RRType::AAAA}, - {"OPT", 41, RRType::OPT}, {"RRSIG", 46, RRType::RRSIG}, - {"DHCID", 49, RRType::DHCID}, {"TKEY", 249, RRType::TKEY}, - {"TSIG", 250, RRType::TSIG}, {"ANY", 255, RRType::ANY}, + {"A", 1, RRType::A}, + {"NS", 2, RRType::NS}, + {"SOA", 6, RRType::SOA}, + {"PTR", 12, RRType::PTR}, + {"TXT", 16, RRType::TXT}, + {"AAAA", 28, RRType::AAAA}, + {"OPT", 41, RRType::OPT}, + {"RRSIG", 46, RRType::RRSIG}, + {"DHCID", 49, RRType::DHCID}, + {"TKEY", 249, RRType::TKEY}, + {"TSIG", 250, RRType::TSIG}, + {"ANY", 255, RRType::ANY}, + {"MD", 3, []() -> const RRType& {static const RRType r("MD"); return (r);}}, + {"MF", 4, []() -> const RRType& {static const RRType r("MF"); return (r);}}, + {"CNAME", 5, []() -> const RRType& {static const RRType r("CNAME"); return (r);}}, + {"MB", 7, []() -> const RRType& {static const RRType r("MB"); return (r);}}, + {"MG", 8, []() -> const RRType& {static const RRType r("MG"); return (r);}}, + {"MR", 9, []() -> const RRType& {static const RRType r("MR"); return (r);}}, + {"NULL", 10, []() -> const RRType& {static const RRType r("NULL"); return (r);}}, + {"WKS", 11, []() -> const RRType& {static const RRType r("WKS"); return (r);}}, + {"HINFO", 13, []() -> const RRType& {static const RRType r("HINFO"); return (r);}}, + {"MINFO", 14, []() -> const RRType& {static const RRType r("MINFO"); return (r);}}, + {"MX", 15, []() -> const RRType& {static const RRType r("MX"); return (r);}}, + {"RP", 17, []() -> const RRType& {static const RRType r("RP"); return (r);}}, + {"AFSDB", 18, []() -> const RRType& {static const RRType r("AFSDB"); return (r);}}, + {"X25", 19, []() -> const RRType& {static const RRType r("X25"); return (r);}}, + {"ISDN", 20, []() -> const RRType& {static const RRType r("ISDN"); return (r);}}, + {"RT", 21, []() -> const RRType& {static const RRType r("RT"); return (r);}}, + {"NSAP", 22, []() -> const RRType& {static const RRType r("NSAP"); return (r);}}, + {"NSAP-PTR", 23, []() -> const RRType& {static const RRType r("NSAP-PTR"); return (r);}}, + {"SIG", 24, []() -> const RRType& {static const RRType r("SIG"); return (r);}}, + {"KEY", 25, []() -> const RRType& {static const RRType r("KEY"); return (r);}}, + {"PX", 26, []() -> const RRType& {static const RRType r("PX"); return (r);}}, + {"GPOS", 27, []() -> const RRType& {static const RRType r("GPOS"); return (r);}}, + {"LOC", 29, []() -> const RRType& {static const RRType r("LOC"); return (r);}}, + {"NXT", 30, []() -> const RRType& {static const RRType r("NXT"); return (r);}}, + {"EID", 31, []() -> const RRType& {static const RRType r("EID"); return (r);}}, + {"NIMLOC", 32, []() -> const RRType& {static const RRType r("NIMLOC"); return (r);}}, + {"SRV", 33, []() -> const RRType& {static const RRType r("SRV"); return (r);}}, + {"ATMA", 34, []() -> const RRType& {static const RRType r("ATMA"); return (r);}}, + {"NAPTR", 35, []() -> const RRType& {static const RRType r("NAPTR"); return (r);}}, + {"KX", 36, []() -> const RRType& {static const RRType r("KX"); return (r);}}, + {"CERT", 37, []() -> const RRType& {static const RRType r("CERT"); return (r);}}, + {"A6", 38, []() -> const RRType& {static const RRType r("A6"); return (r);}}, + {"DNAME", 39, []() -> const RRType& {static const RRType r("DNAME"); return (r);}}, + {"SINK", 40, []() -> const RRType& {static const RRType r("SINK"); return (r);}}, + {"APL", 42, []() -> const RRType& {static const RRType r("APL"); return (r);}}, + {"DS", 43, []() -> const RRType& {static const RRType r("DS"); return (r);}}, + {"SSHFP", 44, []() -> const RRType& {static const RRType r("SSHFP"); return (r);}}, + {"IPSECKEY", 45, []() -> const RRType& {static const RRType r("IPSECKEY"); return (r);}}, + {"NSEC", 47, []() -> const RRType& {static const RRType r("NSEC"); return (r);}}, + {"DNSKEY", 48, []() -> const RRType& {static const RRType r("DNSKEY"); return (r);}}, + {"NSEC3", 50, []() -> const RRType& {static const RRType r("NSEC3"); return (r);}}, + {"NSEC3PARAM", 51, []() -> const RRType& {static const RRType r("NSEC3PARAM"); return (r);}}, + {"TLSA", 52, []() -> const RRType& {static const RRType r("TLSA"); return (r);}}, + {"SMIMEA", 53, []() -> const RRType& {static const RRType r("SMIMEA"); return (r);}}, + // Unassigned 54 + {"HIP", 55, []() -> const RRType& {static const RRType r("HIP"); return (r);}}, + {"NINFO", 56, []() -> const RRType& {static const RRType r("NINFO"); return (r);}}, + {"RKEY", 57, []() -> const RRType& {static const RRType r("RKEY"); return (r);}}, + {"TALINK", 58, []() -> const RRType& {static const RRType r("TALINK"); return (r);}}, + {"CDS", 59, []() -> const RRType& {static const RRType r("CDS"); return (r);}}, + {"CDNSKEY", 60, []() -> const RRType& {static const RRType r("CDNSKEY"); return (r);}}, + {"OPENPGPKEY", 61, []() -> const RRType& {static const RRType r("OPENPGPKEY"); return (r);}}, + {"CSYNC", 62 , []() -> const RRType& {static const RRType r("CSYNC"); return (r);}}, + {"ZONEMD", 63, []() -> const RRType& {static const RRType r("ZONEMD"); return (r);}}, + {"SVCB", 64, []() -> const RRType& {static const RRType r("SVCB"); return (r);}}, + {"HTTPS", 65, []() -> const RRType& {static const RRType r("HTTPS"); return (r);}}, + // Unassigned 66-98 + {"SPF", 99, []() -> const RRType& {static const RRType r("SPF"); return (r);}}, + {"UINFO", 100, []() -> const RRType& {static const RRType r("UINFO"); return (r);}}, + {"UID", 101, []() -> const RRType& {static const RRType r("UID"); return (r);}}, + {"GID", 102, []() -> const RRType& {static const RRType r("GID"); return (r);}}, + {"UNSPEC", 103, []() -> const RRType& {static const RRType r("UNSPEC"); return (r);}}, + {"NID", 104, []() -> const RRType& {static const RRType r("NID"); return (r);}}, + {"L32", 105, []() -> const RRType& {static const RRType r("L32"); return (r);}}, + {"L64", 106, []() -> const RRType& {static const RRType r("L64"); return (r);}}, + {"LP", 107, []() -> const RRType& {static const RRType r("LP"); return (r);}}, + {"EUI48", 108, []() -> const RRType& {static const RRType r("EUI48"); return (r);}}, + {"EUI64", 109, []() -> const RRType& {static const RRType r("EUI64"); return (r);}}, + // Unassigned 110-248 + {"IXFR", 251, []() -> const RRType& {static const RRType r("IXFR"); return (r);}}, + {"AXFR", 252, []() -> const RRType& {static const RRType r("AXFR"); return (r);}}, + {"MAILB", 253, []() -> const RRType& {static const RRType r("MAILB"); return (r);}}, + {"MAILA", 254, []() -> const RRType& {static const RRType r("MAILA"); return (r);}}, + {"ANY", 255, []() -> const RRType& {static const RRType r("ANY"); return (r);}}, // also known as "*" + {"URI", 256, []() -> const RRType& {static const RRType r("URI"); return (r);}}, + {"CAA", 257, []() -> const RRType& {static const RRType r("CAA"); return (r);}}, + {"AVC", 258, []() -> const RRType& {static const RRType r("AVC"); return (r);}}, + {"DOA", 259, []() -> const RRType& {static const RRType r("DOA"); return (r);}}, + {"AMTRELAY", 260, []() -> const RRType& {static const RRType r("AMTRELAY"); return (r);}}, + {"RESINFO", 261, []() -> const RRType& {static const RRType r("RESINFO"); return (r);}}, + // Unassigned 262-32767 + {"TA", 32768, []() -> const RRType& {static const RRType r("TA"); return (r);}}, + {"DLV", 32769, []() -> const RRType& {static const RRType r("DLV"); return (r);}}, {NULL, 0, NULL} }; diff --git a/src/lib/dns/tests/tsig_unittest.cc b/src/lib/dns/tests/tsig_unittest.cc index ca2a28c68e..7f6fa02bc8 100644 --- a/src/lib/dns/tests/tsig_unittest.cc +++ b/src/lib/dns/tests/tsig_unittest.cc @@ -210,9 +210,9 @@ commonSignChecks(ConstTSIGRecordPtr tsig, uint16_t expected_qid, const uint8_t* expected_mac, size_t expected_maclen, uint16_t expected_error = 0, uint16_t expected_otherlen = 0, - const uint8_t* expected_otherdata = NULL, + const uint8_t* expected_otherdata = 0, const Name& expected_algorithm = TSIGKey::HMACMD5_NAME()) { - ASSERT_TRUE(tsig != NULL); + ASSERT_TRUE(tsig); const TSIG& tsig_rdata = tsig->getRdata(); EXPECT_EQ(expected_algorithm, tsig_rdata.getAlgorithm()); @@ -567,7 +567,7 @@ TEST_F(TSIGTest, signContinuation) { // Create and sign the AXFR request ConstTSIGRecordPtr tsig = createMessageAndSign(axfr_qid, zone_name, tsig_ctx.get(), 0, - RRType(252)); + RRType("AXFR")); // Then verify it (the wire format test data should contain the same // message data, and verification should succeed). received_data.clear(); @@ -581,7 +581,7 @@ TEST_F(TSIGTest, signContinuation) { // Create and sign the first response message tsig = createMessageAndSign(axfr_qid, zone_name, tsig_verify_ctx.get(), - AA_FLAG|QR_FLAG, RRType(252), + AA_FLAG|QR_FLAG, RRType("AXFR"), "ns.example.com. root.example.com. " "2011041503 7200 3600 2592000 1200", &RRType::SOA()); @@ -603,7 +603,7 @@ TEST_F(TSIGTest, signContinuation) { { SCOPED_TRACE("Sign test for continued response in TCP stream"); tsig = createMessageAndSign(axfr_qid, zone_name, tsig_verify_ctx.get(), - AA_FLAG|QR_FLAG, RRType(252), + AA_FLAG|QR_FLAG, RRType("AXFR"), "ns.example.com.", &RRType::NS(), false); commonSignChecks(tsig, axfr_qid, 0x4da8e951, expected_mac, sizeof(expected_mac)); diff --git a/src/lib/dns/tsig.cc b/src/lib/dns/tsig.cc index 7281d9ab04..e85d636670 100644 --- a/src/lib/dns/tsig.cc +++ b/src/lib/dns/tsig.cc @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -164,7 +165,7 @@ void TSIGContext::TSIGContextImpl::digestPreviousMAC(HMACPtr hmac) { // We should have ensured the digest size fits 16 bits within this class // implementation. - assert(previous_digest_.size() <= 0xffff); + isc_throw_assert(previous_digest_.size() <= 0xffff); if (previous_digest_.empty()) { // The previous digest was already used. We're in the middle of @@ -400,7 +401,7 @@ TSIGContext::sign(const uint16_t qid, const void* const data, // Get the final digest, update internal state, then finish. vector digest = hmac->sign(impl_->digest_len_); - assert(digest.size() <= 0xffff); // cryptolink API should have ensured it. + isc_throw_assert(digest.size() <= 0xffff); // cryptolink API should have ensured it. ConstTSIGRecordPtr tsig(new TSIGRecord( impl_->key_.getKeyName(), any::TSIG(impl_->key_.getAlgorithmName(),