BIND 10 trac2231, updated. b0414cf54bb6c446c98c3e791d3212b02ff50c8f [2231] Added sanity check for microsecond timeout.
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Sep 11 15:26:13 UTC 2012
The branch, trac2231 has been updated
via b0414cf54bb6c446c98c3e791d3212b02ff50c8f (commit)
from d8dd6f7cb2a0118d692c924d5652d5ec84906117 (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 b0414cf54bb6c446c98c3e791d3212b02ff50c8f
Author: Marcin Siodelski <marcin at isc.org>
Date: Tue Sep 11 17:25:52 2012 +0200
[2231] Added sanity check for microsecond timeout.
-----------------------------------------------------------------------
Summary of changes:
src/lib/dhcp/iface_mgr.cc | 11 ++++++++++-
src/lib/dhcp/iface_mgr.h | 2 ++
src/lib/dhcp/tests/iface_mgr_unittest.cc | 18 ++++++++++++++----
3 files changed, 26 insertions(+), 5 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dhcp/iface_mgr.cc b/src/lib/dhcp/iface_mgr.cc
index cff9f12..0c99647 100644
--- a/src/lib/dhcp/iface_mgr.cc
+++ b/src/lib/dhcp/iface_mgr.cc
@@ -786,7 +786,11 @@ IfaceMgr::send(const Pkt4Ptr& pkt)
boost::shared_ptr<Pkt4>
IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec) {
-
+ // Sanity check for microsecond timeout.
+ if (timeout_usec >= 1000000) {
+ isc_throw(BadValue, "fractional timeout must be shorter than"
+ " one million microseconds");
+ }
const SocketInfo* candidate = 0;
IfaceCollection::const_iterator iface;
fd_set sockets;
@@ -953,6 +957,11 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec) {
}
Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec) {
+ // Sanity check for microsecond timeout.
+ if (timeout_usec >= 1000000) {
+ isc_throw(BadValue, "fractional timeout must be shorter than"
+ " one million microseconds");
+ }
const SocketInfo* candidate = 0;
fd_set sockets;
diff --git a/src/lib/dhcp/iface_mgr.h b/src/lib/dhcp/iface_mgr.h
index cbc254b..922c701 100644
--- a/src/lib/dhcp/iface_mgr.h
+++ b/src/lib/dhcp/iface_mgr.h
@@ -349,6 +349,7 @@ public:
/// @param timeout_usec specifies fractional part of the timeout
/// (in microseconds)
///
+ /// @throw isc::BadValue if timeout_usec is greater than one million
/// @return Pkt6 object representing received packet (or NULL)
Pkt6Ptr receive6(uint32_t timeout_sec, uint32_t timeout_usec = 0);
@@ -362,6 +363,7 @@ public:
/// @param timeout_usec specifies fractional part of the timeout
/// (in microseconds)
///
+ /// @throw isc::BadValue if timeout_usec is greater than one million
/// @return Pkt4 object representing received packet (or NULL)
Pkt4Ptr receive4(uint32_t timeout_sec, uint32_t timeout_usec = 0);
diff --git a/src/lib/dhcp/tests/iface_mgr_unittest.cc b/src/lib/dhcp/tests/iface_mgr_unittest.cc
index 3a05651..3076658 100644
--- a/src/lib/dhcp/tests/iface_mgr_unittest.cc
+++ b/src/lib/dhcp/tests/iface_mgr_unittest.cc
@@ -240,7 +240,8 @@ TEST_F(IfaceMgrTest, receiveTimeout6) {
// Remember when we call receive6().
gettimeofday(&start_time, NULL);
// Call receive with timeout of 1s + 1000us.
- Pkt6Ptr pkt = ifacemgr->receive6(1, 1000);
+ Pkt6Ptr pkt;
+ ASSERT_NO_THROW(pkt = ifacemgr->receive6(1, 1000));
// Remember when call to receive6() ended.
gettimeofday(&stop_time, NULL);
// We did not send a packet to lo interface so we expect that
@@ -256,7 +257,7 @@ TEST_F(IfaceMgrTest, receiveTimeout6) {
// Test timeout shorter than 1s.
gettimeofday(&start_time, NULL);
- pkt = ifacemgr->receive6(0, 500);
+ ASSERT_NO_THROW(pkt = ifacemgr->receive6(0, 500));
gettimeofday(&stop_time, NULL);
ASSERT_FALSE(pkt);
stop_time.tv_sec -= start_time.tv_sec;
@@ -268,6 +269,10 @@ TEST_F(IfaceMgrTest, receiveTimeout6) {
// should be investigated.
EXPECT_EQ(0, stop_time.tv_sec);
EXPECT_GT(stop_time.tv_usec, 500);
+
+ // Test with invalid fractional timeout values.
+ EXPECT_THROW(ifacemgr->receive6(0, 1000000), isc::BadValue);
+ EXPECT_THROW(ifacemgr->receive6(1, 1000010), isc::BadValue);
}
TEST_F(IfaceMgrTest, receiveTimeout4) {
@@ -293,7 +298,8 @@ TEST_F(IfaceMgrTest, receiveTimeout4) {
// Remember when we call receive4().
gettimeofday(&start_time, NULL);
// Call receive with timeout of 2s + 150us.
- Pkt4Ptr pkt = ifacemgr->receive4(2, 150);
+ Pkt4Ptr pkt;
+ ASSERT_NO_THROW(pkt = ifacemgr->receive4(2, 150));
// Remember when call to receive4() ended.
gettimeofday(&stop_time, NULL);
// We did not send a packet to lo interface so we expect that
@@ -309,7 +315,7 @@ TEST_F(IfaceMgrTest, receiveTimeout4) {
// Test timeout shorter than 1s.
gettimeofday(&start_time, NULL);
- pkt = ifacemgr->receive4(0, 350);
+ ASSERT_NO_THROW(pkt = ifacemgr->receive4(0, 350));
gettimeofday(&stop_time, NULL);
ASSERT_FALSE(pkt);
stop_time.tv_sec -= start_time.tv_sec;
@@ -321,6 +327,10 @@ TEST_F(IfaceMgrTest, receiveTimeout4) {
// should be investigated.
EXPECT_EQ(0, stop_time.tv_sec);
EXPECT_GT(stop_time.tv_usec, 350);
+
+ // Test with invalid fractional timeout values.
+ EXPECT_THROW(ifacemgr->receive6(0, 1000000), isc::BadValue);
+ EXPECT_THROW(ifacemgr->receive6(2, 1000005), isc::BadValue);
}
TEST_F(IfaceMgrTest, sockets6) {
More information about the bind10-changes
mailing list