BIND 10 trac1613, updated. 466339143a9161f821fa63e5545ee9cc72d8e1a6 [1613] also test very badly malformed query (and FORMERR counter)

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Feb 16 11:24:05 UTC 2012


The branch, trac1613 has been updated
       via  466339143a9161f821fa63e5545ee9cc72d8e1a6 (commit)
      from  fe5b8226c1d3237ed8feb924ad789cbdbee0287e (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 466339143a9161f821fa63e5545ee9cc72d8e1a6
Author: Jelte Jansen <jelte at isc.org>
Date:   Thu Feb 16 12:23:42 2012 +0100

    [1613] also test very badly malformed query (and FORMERR counter)

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

Summary of changes:
 src/bin/auth/tests/auth_srv_unittest.cc |   26 +++++++++++++++++++++++++-
 src/lib/testutils/srv_test.cc           |   17 +++++++++++++----
 src/lib/testutils/srv_test.h            |    9 ++++++++-
 3 files changed, 46 insertions(+), 6 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/auth/tests/auth_srv_unittest.cc b/src/bin/auth/tests/auth_srv_unittest.cc
index 6bbfe97..77cff86 100644
--- a/src/bin/auth/tests/auth_srv_unittest.cc
+++ b/src/bin/auth/tests/auth_srv_unittest.cc
@@ -85,19 +85,22 @@ protected:
                               &dnsserv);
     }
 
-    // Helper for checking Rcode statistic counters
+    // Helper for checking Rcode statistic counters;
+    // Checks for one specific Rcode statistics counter value
     void checkRcodeCounter(const Rcode& rcode, int expected_value) {
         EXPECT_EQ(expected_value, server.getCounter(rcode)) <<
                   "Expected Rcode count for " << rcode.toText() <<
                   " " << expected_value << ", was: " <<
                   server.getCounter(rcode);
     }
+
     // Checks whether all Rcode counters are set to zero
     void checkAllRcodeCountersZero() {
         for (int i = 0; i < 17; i++) {
             checkRcodeCounter(Rcode(i), 0);
         }
     }
+
     // Checks whether all Rcode counters are set to zero except the given
     // rcode (it is checked to be set to 'value')
     void checkAllRcodeCountersZeroExcept(const Rcode& rcode, int value) {
@@ -174,6 +177,27 @@ TEST_F(AuthSrvTest, builtInQuery) {
     checkAllRcodeCountersZeroExcept(Rcode::NOERROR(), 1);
 }
 
+// Callback used in createRequestMessage that mangles the
+// wiredata to something that should not be parseable (to test
+// really badly formed queries)
+// This specific one simply increments every octet in the array
+void requestMangler(uint8_t* data, size_t data_len) {
+    for (size_t i = 0; i < data_len; ++i) {
+        data[i]++;
+    }
+}
+
+// Same as buildInQuery, but completely malform the sent query
+TEST_F(AuthSrvTest, builtInMalformedQuery) {
+    UnitTestUtil::createRequestMessage(request_message, Opcode::QUERY(),
+                                       default_qid, Name("version.bind"),
+                                       RRClass::CH(), RRType::TXT());
+    createRequestPacket(request_message, IPPROTO_UDP, NULL, &requestMangler);
+    server.processMessage(*io_message, parse_message, response_obuffer,
+                          &dnsserv);
+    checkAllRcodeCountersZeroExcept(Rcode::FORMERR(), 1);
+}
+
 // Same test emulating the UDPServer class behavior (defined in libasiolink).
 // This is not a good test in that it assumes internal implementation details
 // of UDPServer, but we've encountered a regression due to the introduction
diff --git a/src/lib/testutils/srv_test.cc b/src/lib/testutils/srv_test.cc
index dd3e425..ca632d5 100644
--- a/src/lib/testutils/srv_test.cc
+++ b/src/lib/testutils/srv_test.cc
@@ -72,7 +72,8 @@ SrvTestBase::createDataFromFile(const char* const datafile,
 
 void
 SrvTestBase::createRequestPacket(Message& message,
-                                 const int protocol, TSIGContext* context)
+                                    const int protocol, TSIGContext* context,
+                                    void (*callback)(uint8_t*, size_t))
 {
     if (context == NULL) {
         message.toWire(request_renderer);
@@ -86,9 +87,17 @@ SrvTestBase::createRequestPacket(Message& message,
                                   IOAddress(DEFAULT_REMOTE_ADDRESS), 53210);
     io_sock = (protocol == IPPROTO_UDP) ? &IOSocket::getDummyUDPSocket() :
         &IOSocket::getDummyTCPSocket();
-    io_message = new IOMessage(request_renderer.getData(),
-                               request_renderer.getLength(),
-                               *io_sock, *endpoint);
+
+    const void *data = request_renderer.getData();
+    size_t data_len = request_renderer.getLength();
+
+    if (callback) {
+        // convert to non-const uint8_t for easy manipulation by the callback
+        uint8_t *mdata = const_cast<uint8_t*>(static_cast<const uint8_t*>(data));
+        callback(mdata, data_len);
+    }
+    
+    io_message = new IOMessage(data, data_len, *io_sock, *endpoint);
 }
 
 // Unsupported requests.  Should result in NOTIMP.
diff --git a/src/lib/testutils/srv_test.h b/src/lib/testutils/srv_test.h
index 630232c..fe97da7 100644
--- a/src/lib/testutils/srv_test.h
+++ b/src/lib/testutils/srv_test.h
@@ -83,9 +83,16 @@ protected:
     /// It constructs wire-format DNS packet data from \c message in the
     /// form of \c IOMessage in \c io_message.
     /// The existing content of \c io_message, if any, will be deleted.
+    ///
+    /// If callback is given, it is called after rendering the message,
+    /// but before 'sending' it; this allows the given callback to modify
+    /// the data and introduce bad requests that would otherwise be hard
+    /// to reproduce (it passes the wire-format data as non-const uint8_t,
+    /// so tread lightly when using this).
     void createRequestPacket(isc::dns::Message& message,
                              const int protocol = IPPROTO_UDP,
-                             isc::dns::TSIGContext* context = NULL);
+                             isc::dns::TSIGContext* context = NULL,
+                             void (*callback)(uint8_t*, size_t) = NULL);
 
     MockSession notify_session;
     MockServer dnsserv;




More information about the bind10-changes mailing list