BIND 10 trac1784, updated. 8db9dee3621661108c12faedf26bfaf9381c13bb [1784] reject unsupported addServer options.
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Mar 19 17:03:39 UTC 2012
The branch, trac1784 has been updated
via 8db9dee3621661108c12faedf26bfaf9381c13bb (commit)
via 02cb1de4a0e0d3c12bc29aa7686a9015dadc637d (commit)
from 438bcd6747bf177dfd6355c77c06d28560a1369a (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 8db9dee3621661108c12faedf26bfaf9381c13bb
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Mon Mar 19 10:03:21 2012 -0700
[1784] reject unsupported addServer options.
commit 02cb1de4a0e0d3c12bc29aa7686a9015dadc637d
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Mon Mar 19 09:48:40 2012 -0700
[1784] added some notes about why we do null check for 'res' from getaddrinfo.
-----------------------------------------------------------------------
Summary of changes:
src/lib/asiodns/dns_service.cc | 6 ++++++
src/lib/asiodns/dns_service.h | 10 +++++++++-
src/lib/asiodns/tests/dns_service_unittest.cc | 13 +++++++++++++
3 files changed, 28 insertions(+), 1 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/asiodns/dns_service.cc b/src/lib/asiodns/dns_service.cc
index e6e3bfa..1710922 100644
--- a/src/lib/asiodns/dns_service.cc
+++ b/src/lib/asiodns/dns_service.cc
@@ -22,6 +22,8 @@
#include <log/dummylog.h>
+#include <exceptions/exceptions.h>
+
#include <asio.hpp>
#include <dns_service.h>
#include <asiolink/io_service.h>
@@ -208,6 +210,10 @@ void DNSService::addServerTCPFromFD(int fd, int af) {
}
void DNSService::addServerUDPFromFD(int fd, int af, ServerFlag options) {
+ if ((~SERVER_DEFINED_FLAGS & static_cast<int>(options)) != 0) {
+ isc_throw(isc::InvalidParameter, "Invalid DNS/UDP server option: "
+ << options);
+ }
if ((options & SERVER_SYNC_OK) != 0) {
impl_->addServerFromFD<DNSServiceImpl::SyncUDPServerPtr,
SyncUDPServer>(fd, af);
diff --git a/src/lib/asiodns/dns_service.h b/src/lib/asiodns/dns_service.h
index 865aee4..161658f 100644
--- a/src/lib/asiodns/dns_service.h
+++ b/src/lib/asiodns/dns_service.h
@@ -75,6 +75,7 @@ public:
///< information given by the client.
};
+public:
/// \brief The destructor.
virtual ~DNSServiceBase() {}
@@ -104,6 +105,12 @@ private:
DNSService(const DNSService& source);
DNSService& operator=(const DNSService& source);
+private:
+ // Bit or'ed all defined \c ServerFlag values. Used internally for
+ // compatibility check. Note that this doesn't have to be used by
+ // applications, and doesn't have to be defined in the "base" class.
+ static const unsigned int SERVER_DEFINED_FLAGS = 1;
+
public:
/// \brief The constructor with a specific IP address and port on which
/// the services listen on.
@@ -187,7 +194,8 @@ public:
/// AF_INET or AF_INET6.
/// \param options Optional properties of the server (see ServerFlag).
///
- /// \throw isc::InvalidParameter if af is neither AF_INET nor AF_INET6.
+ /// \throw isc::InvalidParameter if af is neither AF_INET nor AF_INET6,
+ /// or the given \c options include an unsupported or invalid value.
/// \throw isc::asiolink::IOError when a low-level error happens, like the
/// fd is not a valid descriptor or it can't be listened on.
virtual void addServerUDPFromFD(int fd, int af,
diff --git a/src/lib/asiodns/tests/dns_service_unittest.cc b/src/lib/asiodns/tests/dns_service_unittest.cc
index 931c59a..beac02b 100644
--- a/src/lib/asiodns/tests/dns_service_unittest.cc
+++ b/src/lib/asiodns/tests/dns_service_unittest.cc
@@ -15,6 +15,8 @@
#include <config.h>
#include <gtest/gtest.h>
+#include <exceptions/exceptions.h>
+
#include <asio.hpp>
#include <asiolink/asiolink.h>
#include <asiodns/asiodns.h>
@@ -257,6 +259,9 @@ getSocketFD(int family, const char* const address, const char* const port) {
int s = -1;
int error = getaddrinfo(address, port, &hints, &res);
if (error == 0) {
+ // If getaddrinfo returns 0, res should be set to a non NULL valid
+ // pointer, but some variants of cppcheck reportedly complains about
+ // it, so we satisfy them here.
if (res != NULL) {
s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (s >= 0) {
@@ -307,4 +312,12 @@ TEST_F(UDPDNSServiceTest, syncUDPServerFromFD) {
EXPECT_EQ(first_buffer_, second_buffer_);
}
+TEST_F(UDPDNSServiceTest, addUDPServerFromFDWithUnknownOption) {
+ // Use of undefined/incompatible options should result in an exception.
+ EXPECT_THROW(dns_service.addServerUDPFromFD(
+ getSocketFD(AF_INET6, TEST_IPV6_ADDR, TEST_SERVER_PORT),
+ AF_INET6, static_cast<DNSService::ServerFlag>(2)),
+ isc::InvalidParameter);
+}
+
} // unnamed namespace
More information about the bind10-changes
mailing list