From: JINMEI Tatuya Date: Mon, 19 Mar 2012 17:03:21 +0000 (-0700) Subject: [1784] reject unsupported addServer options. X-Git-Tag: trac2351_base~226^2~116^2~100^2~5^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8db9dee3621661108c12faedf26bfaf9381c13bb;p=thirdparty%2Fkea.git [1784] reject unsupported addServer options. --- diff --git a/src/lib/asiodns/dns_service.cc b/src/lib/asiodns/dns_service.cc index e6e3bfa949..1710922345 100644 --- a/src/lib/asiodns/dns_service.cc +++ b/src/lib/asiodns/dns_service.cc @@ -22,6 +22,8 @@ #include +#include + #include #include #include @@ -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(options)) != 0) { + isc_throw(isc::InvalidParameter, "Invalid DNS/UDP server option: " + << options); + } if ((options & SERVER_SYNC_OK) != 0) { impl_->addServerFromFD(fd, af); diff --git a/src/lib/asiodns/dns_service.h b/src/lib/asiodns/dns_service.h index 865aee4f89..161658fba9 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 fd424b479d..beac02b245 100644 --- a/src/lib/asiodns/tests/dns_service_unittest.cc +++ b/src/lib/asiodns/tests/dns_service_unittest.cc @@ -15,6 +15,8 @@ #include #include +#include + #include #include #include @@ -310,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(2)), + isc::InvalidParameter); +} + } // unnamed namespace