Parcourir la source

[2387] Support empty bitmaps in buildBitmapsFromLexer()

This avoids an extra ungetToken() and cuts down on some code too.
Mukund Sivaraman il y a 12 ans
Parent
commit
0ecc1e01cd

+ 5 - 1
src/lib/dns/rdata/generic/detail/nsec_bitmap.cc

@@ -79,7 +79,8 @@ checkRRTypeBitmaps(const char* const rrtype_name,
 
 void
 buildBitmapsFromLexer(const char* const rrtype_name,
-                      MasterLexer& lexer, vector<uint8_t>& typebits)
+                      MasterLexer& lexer, vector<uint8_t>& typebits,
+                      bool allow_empty)
 {
     uint8_t bitmap[8 * 1024];       // 64k bits
     memset(bitmap, 0, sizeof(bitmap));
@@ -112,6 +113,9 @@ buildBitmapsFromLexer(const char* const rrtype_name,
     lexer.ungetToken();
 
     if (!have_rrtypes) {
+         if (allow_empty) {
+              return;
+         }
          isc_throw(InvalidRdataText,
                    rrtype_name << " record does not end with RR type mnemonic");
     }

+ 7 - 2
src/lib/dns/rdata/generic/detail/nsec_bitmap.h

@@ -57,7 +57,8 @@ void checkRRTypeBitmaps(const char* const rrtype_name,
 /// \brief Convert textual sequence of RR types read from a lexer into
 /// type bitmaps.
 ///
-/// See the other variant above for description.
+/// See the other variant above for description. If \c allow_empty is
+/// true and there are no mnemonics, \c typebits is left untouched.
 ///
 /// \exception InvalidRdataText Data read from the given lexer does not
 /// meet the assumption (e.g. including invalid form of RR type, not
@@ -70,9 +71,13 @@ void checkRRTypeBitmaps(const char* const rrtype_name,
 /// bits are set.
 /// \param typebits A placeholder for the resulting bitmaps.  Expected to be
 /// empty, but it's not checked.
+/// \param allow_empty If true, the function simply returns if no RR
+/// type mnemonics are found. Otherwise, it throws an exception if no RR
+/// type mnemonics are found.
 void buildBitmapsFromLexer(const char* const rrtype_name,
                            isc::dns::MasterLexer& lexer,
-                           std::vector<uint8_t>& typebits);
+                           std::vector<uint8_t>& typebits,
+                           bool allow_empty = false);
 
 /// \brief Convert type bitmaps to textual sequence of RR types.
 ///

+ 2 - 19
src/lib/dns/rdata/generic/nsec3_50.cc

@@ -144,26 +144,9 @@ NSEC3::constructFromLexer(MasterLexer& lexer) {
                   << next.size() << " bytes");
     }
 
-    // For NSEC3 empty bitmap is possible and allowed.
-    bool empty_bitmap = false;
-    const MasterToken& token = lexer.getNextToken();
-    if ((token.getType() == MasterToken::END_OF_LINE) ||
-        (token.getType() == MasterToken::END_OF_FILE)) {
-         empty_bitmap = true;
-    }
-
-    lexer.ungetToken();
-
-    if (empty_bitmap) {
-        impl_ = new NSEC3Impl(params.algorithm, params.flags,
-                              params.iterations, salt, next,
-                              vector<uint8_t>());
-        return;
-    }
-
     vector<uint8_t> typebits;
-    buildBitmapsFromLexer("NSEC3", lexer, typebits);
-
+    // For NSEC3 empty bitmap is possible and allowed.
+    buildBitmapsFromLexer("NSEC3", lexer, typebits, true);
     impl_ = new NSEC3Impl(params.algorithm, params.flags, params.iterations,
                           salt, next, typebits);
 }