BIND 10 trac2000, updated. e2c4caa23971f3ebd70483ccc9c0b9ba8b7efa2e [2000] Add more fromWire() tests
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Jan 27 07:57:26 UTC 2014
The branch, trac2000 has been updated
via e2c4caa23971f3ebd70483ccc9c0b9ba8b7efa2e (commit)
from b6875c7848cf648d45d0448ba8aa3f30a281d3c4 (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 e2c4caa23971f3ebd70483ccc9c0b9ba8b7efa2e
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Jan 27 12:31:53 2014 +0530
[2000] Add more fromWire() tests
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/rdata/generic/opt_41.cc | 10 +++++---
src/lib/dns/tests/rdata_opt_unittest.cc | 25 ++++++++++++++++----
src/lib/dns/tests/testdata/Makefile.am | 4 +++-
.../{rdata_opt_fromWire => rdata_opt_fromWire1} | 0
src/lib/dns/tests/testdata/rdata_opt_fromWire2 | 4 ++++
src/lib/dns/tests/testdata/rdata_opt_fromWire3 | 8 +++++++
src/lib/dns/tests/testdata/rdata_opt_fromWire4 | 9 +++++++
7 files changed, 51 insertions(+), 9 deletions(-)
rename src/lib/dns/tests/testdata/{rdata_opt_fromWire => rdata_opt_fromWire1} (100%)
create mode 100644 src/lib/dns/tests/testdata/rdata_opt_fromWire2
create mode 100644 src/lib/dns/tests/testdata/rdata_opt_fromWire3
create mode 100644 src/lib/dns/tests/testdata/rdata_opt_fromWire4
-----------------------------------------------------------------------
diff --git a/src/lib/dns/rdata/generic/opt_41.cc b/src/lib/dns/rdata/generic/opt_41.cc
index 167c309..176fa39 100644
--- a/src/lib/dns/rdata/generic/opt_41.cc
+++ b/src/lib/dns/rdata/generic/opt_41.cc
@@ -111,7 +111,9 @@ OPT::OPT(InputBuffer& buffer, size_t rdata_len) :
const uint16_t option_length = buffer.readUint16();
rdata_len -= 4;
- if ((impl_ptr->rdlength_ + option_length) < impl_ptr->rdlength_) {
+ if (static_cast<uint16_t>(impl_ptr->rdlength_ + option_length) <
+ impl_ptr->rdlength_)
+ {
isc_throw(InvalidRdataText,
"Option length " << option_length
<< " would overflow OPT RR RDLEN (currently "
@@ -119,7 +121,7 @@ OPT::OPT(InputBuffer& buffer, size_t rdata_len) :
}
if (rdata_len < option_length) {
- isc_throw(InvalidRdataLength, "Corrupt Pseudo OPT RR record");
+ isc_throw(InvalidRdataLength, "Corrupt pseudo OPT RR record");
}
boost::shared_ptr<std::vector<uint8_t> >
@@ -184,7 +186,9 @@ OPT::appendPseudoRR(uint16_t code, const uint8_t* data, uint16_t length) {
// See if it overflows 16-bit length field. We only worry about the
// pseudo-RR length here, not the whole message length (which should
// be checked and enforced elsewhere).
- if ((impl_->rdlength_ + length) < impl_->rdlength_) {
+ if (static_cast<uint16_t>(impl_->rdlength_ + length) <
+ impl_->rdlength_)
+ {
isc_throw(isc::InvalidParameter,
"Option length " << length
<< " would overflow OPT RR RDLEN (currently "
diff --git a/src/lib/dns/tests/rdata_opt_unittest.cc b/src/lib/dns/tests/rdata_opt_unittest.cc
index 900c672..6f703bf 100644
--- a/src/lib/dns/tests/rdata_opt_unittest.cc
+++ b/src/lib/dns/tests/rdata_opt_unittest.cc
@@ -46,12 +46,27 @@ TEST_F(Rdata_OPT_Test, createFromWire) {
// Valid cases: in the simple implementation with no supported options,
// we can only check these don't throw.
EXPECT_NO_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass("CLASS4096"),
- "rdata_opt_fromWire"));
+ "rdata_opt_fromWire1"));
EXPECT_NO_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass::CH(),
- "rdata_opt_fromWire", 2));
+ "rdata_opt_fromWire1", 2));
+
+ // Short RDLEN. This throws InvalidRdataLength even if subsequent
+ // pseudo RRs cause RDLEN size to be exhausted.
+ EXPECT_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass::IN(),
+ "rdata_opt_fromWire2"),
+ InvalidRdataLength);
+ EXPECT_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass::IN(),
+ "rdata_opt_fromWire3"),
+ InvalidRdataLength);
+ // Option lengths can add up and overflow RDLEN. Unlikely when
+ // parsed from wire data, but we'll check for it anyway.
+ EXPECT_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass::IN(),
+ "rdata_opt_fromWire4"),
+ InvalidRdataText);
+
// short buffer case.
EXPECT_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass::IN(),
- "rdata_opt_fromWire", 11),
+ "rdata_opt_fromWire1", 11),
InvalidBufferPosition);
}
@@ -80,7 +95,7 @@ TEST_F(Rdata_OPT_Test, toText) {
TEST_F(Rdata_OPT_Test, compare) {
EXPECT_THROW(rdata_opt.compare(
*rdataFactoryFromFile(RRType::OPT(), RRClass::CH(),
- "rdata_opt_fromWire", 2)),
+ "rdata_opt_fromWire1", 2)),
isc::InvalidOperation);
// comparison attempt between incompatible RR types also results in
@@ -98,7 +113,7 @@ TEST_F(Rdata_OPT_Test, getPseudoRRs) {
const generic::OPT rdf =
dynamic_cast<const generic::OPT&>
(*rdataFactoryFromFile(RRType("OPT"), RRClass("IN"),
- "rdata_opt_fromWire", 2));
+ "rdata_opt_fromWire1", 2));
const std::vector<generic::OPT::PseudoRR>& rrs = rdf.getPseudoRRs();
ASSERT_FALSE(rrs.empty());
diff --git a/src/lib/dns/tests/testdata/Makefile.am b/src/lib/dns/tests/testdata/Makefile.am
index b6d7e35..99a124a 100644
--- a/src/lib/dns/tests/testdata/Makefile.am
+++ b/src/lib/dns/tests/testdata/Makefile.am
@@ -127,7 +127,9 @@ EXTRA_DIST += rdata_nsec3_fromWire10.spec rdata_nsec3_fromWire11.spec
EXTRA_DIST += rdata_nsec3_fromWire12.spec rdata_nsec3_fromWire13.spec
EXTRA_DIST += rdata_nsec3_fromWire14.spec rdata_nsec3_fromWire15.spec
EXTRA_DIST += rdata_nsec3_fromWire16.spec rdata_nsec3_fromWire17.spec
-EXTRA_DIST += rdata_opt_fromWire rdata_rrsig_fromWire1
+EXTRA_DIST += rdata_opt_fromWire1 rdata_opt_fromWire2
+EXTRA_DIST += rdata_opt_fromWire3 rdata_opt_fromWire4
+EXTRA_DIST += rdata_rrsig_fromWire1
EXTRA_DIST += rdata_rrsig_fromWire2.spec
EXTRA_DIST += rdata_rp_fromWire1.spec rdata_rp_fromWire2.spec
EXTRA_DIST += rdata_rp_fromWire3.spec rdata_rp_fromWire4.spec
diff --git a/src/lib/dns/tests/testdata/rdata_opt_fromWire b/src/lib/dns/tests/testdata/rdata_opt_fromWire
deleted file mode 100644
index 0ca5f6a..0000000
--- a/src/lib/dns/tests/testdata/rdata_opt_fromWire
+++ /dev/null
@@ -1,16 +0,0 @@
-#
-# various kinds of OPT RDATA stored in an input buffer
-#
-# empty RDATA (which is okay)
-#
-# 0 1 (bytes)
- 00 00
-#
-# an OPT RR containing an NSID Option
-# code=3 len=3 ID value (opaque)
-# 2 3 4 5 6 7 8 9 10
- 00 07 00 03 00 03 00 01 02
-#
-# short buffer (this can be tested only at the end of the buffer)
-# 1 2 3 4 5
- 00 04 c0 00 02
diff --git a/src/lib/dns/tests/testdata/rdata_opt_fromWire1 b/src/lib/dns/tests/testdata/rdata_opt_fromWire1
new file mode 100644
index 0000000..0ca5f6a
--- /dev/null
+++ b/src/lib/dns/tests/testdata/rdata_opt_fromWire1
@@ -0,0 +1,16 @@
+#
+# various kinds of OPT RDATA stored in an input buffer
+#
+# empty RDATA (which is okay)
+#
+# 0 1 (bytes)
+ 00 00
+#
+# an OPT RR containing an NSID Option
+# code=3 len=3 ID value (opaque)
+# 2 3 4 5 6 7 8 9 10
+ 00 07 00 03 00 03 00 01 02
+#
+# short buffer (this can be tested only at the end of the buffer)
+# 1 2 3 4 5
+ 00 04 c0 00 02
diff --git a/src/lib/dns/tests/testdata/rdata_opt_fromWire2 b/src/lib/dns/tests/testdata/rdata_opt_fromWire2
new file mode 100644
index 0000000..4f5945c
--- /dev/null
+++ b/src/lib/dns/tests/testdata/rdata_opt_fromWire2
@@ -0,0 +1,4 @@
+# short RDATA length
+#
+# OPT RDATA, RDLEN=1
+0001
diff --git a/src/lib/dns/tests/testdata/rdata_opt_fromWire3 b/src/lib/dns/tests/testdata/rdata_opt_fromWire3
new file mode 100644
index 0000000..5ec2def
--- /dev/null
+++ b/src/lib/dns/tests/testdata/rdata_opt_fromWire3
@@ -0,0 +1,8 @@
+# short RDATA length (in second pseudo RR)
+#
+# OPT RDATA, RDLEN=8
+0008
+# psuedo RR 1 of size 7 (code=3, len=3)
+00 03 00 03 00 01 02
+# psuedo RR 2 of size 7 exhausts RDLEN (code=4, len=3)
+00 04 00 03 00 01 02
diff --git a/src/lib/dns/tests/testdata/rdata_opt_fromWire4 b/src/lib/dns/tests/testdata/rdata_opt_fromWire4
new file mode 100644
index 0000000..1b388c3
--- /dev/null
+++ b/src/lib/dns/tests/testdata/rdata_opt_fromWire4
@@ -0,0 +1,9 @@
+# Sum of option lengths would overflow RDLEN
+#
+# OPT RDATA, RDLEN=14 (0x000e)
+000e
+# psuedo RR 1 (code=3, len=3)
+00 03 00 03 00 01 02
+# psuedo RR 2 (code=4, len=65535 overflows RDLEN)
+00 04 ff ff 00 01 02
+# rest of option data is omitted...
More information about the bind10-changes
mailing list