BIND 10 trac2497, updated. 1a2787f32f2376d76367516f5cfb3a0059b76474 [2497] Fix HINFO parsing in the string parser

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Dec 3 23:11:02 UTC 2012


The branch, trac2497 has been updated
       via  1a2787f32f2376d76367516f5cfb3a0059b76474 (commit)
       via  7237139f1b8ec9248fa26e9ae2e6987bfb54f288 (commit)
      from  3e5f22520515b1f1675c3217ff686106201fdfdf (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1a2787f32f2376d76367516f5cfb3a0059b76474
Author: Mukund Sivaraman <muks at isc.org>
Date:   Tue Dec 4 04:23:36 2012 +0530

    [2497] Fix HINFO parsing in the string parser
    
    The lexer variant also uses the string parser eventually (for now).

commit 7237139f1b8ec9248fa26e9ae2e6987bfb54f288
Author: Mukund Sivaraman <muks at isc.org>
Date:   Tue Dec 4 04:13:57 2012 +0530

    [2497] Return whether the string is quoted in characterstr::getNextCharacterString()

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dns/character_string.cc                |    7 ++++++-
 src/lib/dns/character_string.h                 |    5 ++++-
 src/lib/dns/rdata/generic/hinfo_13.cc          |   24 ++++++++++++++++++------
 src/lib/dns/rdata/generic/hinfo_13.h           |    9 ++++++++-
 src/lib/dns/tests/character_string_unittest.cc |    7 ++++++-
 src/lib/dns/tests/rdata_hinfo_unittest.cc      |   17 +++++++++++++----
 6 files changed, 55 insertions(+), 14 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/character_string.cc b/src/lib/dns/character_string.cc
index 3a289ac..8b31948 100644
--- a/src/lib/dns/character_string.cc
+++ b/src/lib/dns/character_string.cc
@@ -29,7 +29,8 @@ bool isDigit(char c) {
 
 std::string
 characterstr::getNextCharacterString(const std::string& input_str,
-                              std::string::const_iterator& input_iterator)
+                              std::string::const_iterator& input_iterator,
+                              bool* quoted)
 {
     string result;
 
@@ -119,6 +120,10 @@ characterstr::getNextCharacterString(const std::string& input_str,
         isc_throw(InvalidRdataText, "The quotes are not paired");
     }
 
+    if (quoted != NULL) {
+        *quoted = quotes_separated;
+    }
+
     return (result);
 }
 
diff --git a/src/lib/dns/character_string.h b/src/lib/dns/character_string.h
index 2a68778..0bfa38b 100644
--- a/src/lib/dns/character_string.h
+++ b/src/lib/dns/character_string.h
@@ -39,9 +39,12 @@ namespace characterstr {
     /// \param input_iterator The iterator from which to start extracting,
     ///        the iterator will be updated to new position after the function
     ///        is returned
+    /// \param quoted If not \c NULL, returns \c true at this address if
+    ///        the string is quoted, \cfalse otherwise
     /// \return A std::string that contains the extracted <character-string>
     std::string getNextCharacterString(const std::string& input_str,
-                                       std::string::const_iterator& input_iterator);
+                                       std::string::const_iterator& input_iterator,
+                                       bool* quoted = NULL);
 
     /// Get a <character-string> from a input buffer
     ///
diff --git a/src/lib/dns/rdata/generic/hinfo_13.cc b/src/lib/dns/rdata/generic/hinfo_13.cc
index 12f034c..77bfdfd 100644
--- a/src/lib/dns/rdata/generic/hinfo_13.cc
+++ b/src/lib/dns/rdata/generic/hinfo_13.cc
@@ -39,11 +39,22 @@ using namespace isc::dns::characterstr;
 
 HINFO::HINFO(const std::string& hinfo_str) {
     string::const_iterator input_iterator = hinfo_str.begin();
-    cpu_ = getNextCharacterString(hinfo_str, input_iterator);
 
-    skipLeftSpaces(hinfo_str, input_iterator);
+    bool quoted;
+    cpu_ = getNextCharacterString(hinfo_str, input_iterator, &quoted);
+
+    skipLeftSpaces(hinfo_str, input_iterator, quoted);
 
     os_ = getNextCharacterString(hinfo_str, input_iterator);
+
+    // Skip whitespace at the end.
+    while (input_iterator < hinfo_str.end() && isspace(*input_iterator)) {
+        ++input_iterator;
+    }
+    if (input_iterator < hinfo_str.end()) {
+        isc_throw(InvalidRdataText,
+                  "Invalid HINFO text format: too many fields.");
+    }
 }
 
 HINFO::HINFO(InputBuffer& buffer, size_t rdata_len) {
@@ -108,16 +119,17 @@ HINFO::getOS() const {
 
 void
 HINFO::skipLeftSpaces(const std::string& input_str,
-                      std::string::const_iterator& input_iterator)
+                      std::string::const_iterator& input_iterator,
+                      bool optional)
 {
     if (input_iterator >= input_str.end()) {
         isc_throw(InvalidRdataText,
-                  "Invalid HINFO text format, field is missing.");
+                  "Invalid HINFO text format: field is missing.");
     }
 
-    if (!isspace(*input_iterator)) {
+    if (!isspace(*input_iterator) && !optional) {
         isc_throw(InvalidRdataText,
-            "Invalid HINFO text format, fields are not separated by space.");
+            "Invalid HINFO text format: fields are not separated by space.");
     }
     // Skip white spaces
     while (input_iterator < input_str.end() && isspace(*input_iterator)) {
diff --git a/src/lib/dns/rdata/generic/hinfo_13.h b/src/lib/dns/rdata/generic/hinfo_13.h
index 8513419..5534a7e 100644
--- a/src/lib/dns/rdata/generic/hinfo_13.h
+++ b/src/lib/dns/rdata/generic/hinfo_13.h
@@ -46,10 +46,17 @@ public:
 private:
     /// Skip the left whitespaces of the input string
     ///
+    /// If \c optional argument is \c true and no spaces occur at the
+    /// current location, then nothing happens. If \c optional is
+    /// \c false and no spaces occur at the current location, then
+    /// the \c InvalidRdataText exception is thrown.
+    ///
     /// \param input_str The input string
     /// \param input_iterator From which the skipping started
+    /// \param optional If true, the spaces are optionally skipped.
     void skipLeftSpaces(const std::string& input_str,
-                        std::string::const_iterator& input_iterator);
+                        std::string::const_iterator& input_iterator,
+                        bool optional);
 
     /// Helper template function for toWire()
     ///
diff --git a/src/lib/dns/tests/character_string_unittest.cc b/src/lib/dns/tests/character_string_unittest.cc
index 5fed9eb..e8f5884 100644
--- a/src/lib/dns/tests/character_string_unittest.cc
+++ b/src/lib/dns/tests/character_string_unittest.cc
@@ -33,11 +33,13 @@ class CharacterString {
 public:
     CharacterString(const string& str){
         string::const_iterator it = str.begin();
-        characterStr_ = getNextCharacterString(str, it);
+        characterStr_ = getNextCharacterString(str, it, &is_quoted_);
     }
     const string& str() const { return characterStr_; }
+    bool quoted() const { return (is_quoted_); }
 private:
     string characterStr_;
+    bool is_quoted_;
 };
 
 TEST(CharacterStringTest, testNormalCase) {
@@ -47,14 +49,17 @@ TEST(CharacterStringTest, testNormalCase) {
     // Test <character-string> that separated by space
     CharacterString cstr2("foo bar");
     EXPECT_EQ(string("foo"), cstr2.str());
+    EXPECT_FALSE(cstr2.quoted());
 
     // Test <character-string> that separated by quotes
     CharacterString cstr3("\"foo bar\"");
     EXPECT_EQ(string("foo bar"), cstr3.str());
+    EXPECT_TRUE(cstr3.quoted());
 
     // Test <character-string> that not separate by quotes but ended with quotes
     CharacterString cstr4("foo\"");
     EXPECT_EQ(string("foo\""), cstr4.str());
+    EXPECT_FALSE(cstr4.quoted());
 }
 
 TEST(CharacterStringTest, testBadCase) {
diff --git a/src/lib/dns/tests/rdata_hinfo_unittest.cc b/src/lib/dns/tests/rdata_hinfo_unittest.cc
index 7469047..0055639 100644
--- a/src/lib/dns/tests/rdata_hinfo_unittest.cc
+++ b/src/lib/dns/tests/rdata_hinfo_unittest.cc
@@ -57,8 +57,11 @@ TEST_F(Rdata_HINFO_Test, createFromText) {
 }
 
 TEST_F(Rdata_HINFO_Test, badText) {
-    // Fields must be seperated by spaces
-    EXPECT_THROW(const HINFO hinfo("\"Pentium\"\"Linux\""), InvalidRdataText);
+    // Only 2 fields must exist
+    EXPECT_THROW(const HINFO hinfo("\"Pentium\"\"Linux\"\"Computer\""),
+                 InvalidRdataText);
+    EXPECT_THROW(const HINFO hinfo("\"Pentium\" \"Linux\" \"Computer\""),
+                 InvalidRdataText);
     // Field cannot be missing
     EXPECT_THROW(const HINFO hinfo("Pentium"), InvalidRdataText);
     // The <character-string> cannot exceed 255 characters
@@ -82,10 +85,16 @@ TEST_F(Rdata_HINFO_Test, createFromLexer) {
     EXPECT_EQ(0, rdata_hinfo.compare(
         *test::createRdataUsingLexer(RRType::HINFO(), RRClass::IN(),
                                      hinfo_str)));
-
+    EXPECT_EQ(0, rdata_hinfo.compare(
+        *test::createRdataUsingLexer(RRType::HINFO(), RRClass::IN(),
+                                     "\"Pentium\"\"Linux\"")));
     // Exceptions cause NULL to be returned.
     EXPECT_FALSE(test::createRdataUsingLexer(RRType::HINFO(), RRClass::IN(),
-                                             "\"Pentium\"\"Linux\""));
+                                             "\"Pentium\"\"Linux\""
+                                             "\"Computer\""));
+    EXPECT_FALSE(test::createRdataUsingLexer(RRType::HINFO(), RRClass::IN(),
+                                             "\"Pentium\" \"Linux\" "
+                                             "\"Computer\""));
 }
 
 TEST_F(Rdata_HINFO_Test, toText) {



More information about the bind10-changes mailing list