BIND 10 trac2124, updated. 5e7af00c87fdb082fcaf024727de244a822513c5 [2124] Add some more wire data tests
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Jul 23 06:15:58 UTC 2012
The branch, trac2124 has been updated
via 5e7af00c87fdb082fcaf024727de244a822513c5 (commit)
via 25e34715a248f5ef26648093be23a391438a84f4 (commit)
via 63c345f54424efeabf4e6e40ff9f62eee9f8b59e (commit)
via 2d714adfc87c6f8d5e20d408eec1a521605c127f (commit)
via d0d70f211833ccd8071704d3fec8858e79f4304d (commit)
via 045ede28af3d51c72a5333bd8069d90c3e91a46f (commit)
from d448a7e8c847e7842e5cb3c92e8ea673fba9544d (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 5e7af00c87fdb082fcaf024727de244a822513c5
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Jul 23 11:44:59 2012 +0530
[2124] Add some more wire data tests
commit 25e34715a248f5ef26648093be23a391438a84f4
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Jul 23 11:23:31 2012 +0530
[2124] Add more tests (check >255)
commit 63c345f54424efeabf4e6e40ff9f62eee9f8b59e
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Jul 23 11:20:40 2012 +0530
[2124] Catch isc::BadValue and throw InvalidRdataText instead
commit 2d714adfc87c6f8d5e20d408eec1a521605c127f
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Jul 23 11:11:40 2012 +0530
[2124] Shorten rdata
commit d0d70f211833ccd8071704d3fec8858e79f4304d
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Jul 23 11:03:57 2012 +0530
[2124] Check that algorithm and fingerprint are in the range [1,255]
commit 045ede28af3d51c72a5333bd8069d90c3e91a46f
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Jul 23 11:03:25 2012 +0530
[2124] Indent code according to our coding style
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/rdata/generic/sshfp_44.cc | 50 ++++++++++++++---
src/lib/dns/tests/rdata_sshfp_unittest.cc | 57 +++++++++++++++-----
src/lib/dns/tests/testdata/.gitignore | 5 ++
src/lib/dns/tests/testdata/Makefile.am | 6 +++
...p_fromWire2.spec => rdata_sshfp_fromWire3.spec} | 2 +
...p_fromWire2.spec => rdata_sshfp_fromWire4.spec} | 2 +
...p_fromWire2.spec => rdata_sshfp_fromWire5.spec} | 2 +
...p_fromWire2.spec => rdata_sshfp_fromWire6.spec} | 2 +
...p_fromWire2.spec => rdata_sshfp_fromWire7.spec} | 2 +
9 files changed, 107 insertions(+), 21 deletions(-)
copy src/lib/dns/tests/testdata/{rdata_sshfp_fromWire2.spec => rdata_sshfp_fromWire3.spec} (76%)
copy src/lib/dns/tests/testdata/{rdata_sshfp_fromWire2.spec => rdata_sshfp_fromWire4.spec} (75%)
copy src/lib/dns/tests/testdata/{rdata_sshfp_fromWire2.spec => rdata_sshfp_fromWire5.spec} (76%)
copy src/lib/dns/tests/testdata/{rdata_sshfp_fromWire2.spec => rdata_sshfp_fromWire6.spec} (76%)
copy src/lib/dns/tests/testdata/{rdata_sshfp_fromWire2.spec => rdata_sshfp_fromWire7.spec} (73%)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/rdata/generic/sshfp_44.cc b/src/lib/dns/rdata/generic/sshfp_44.cc
index 5d65b00..ef69789 100644
--- a/src/lib/dns/rdata/generic/sshfp_44.cc
+++ b/src/lib/dns/rdata/generic/sshfp_44.cc
@@ -37,12 +37,20 @@ using namespace isc::util::encode;
SSHFP::SSHFP(InputBuffer& buffer, size_t rdata_len) {
if (rdata_len < 2) {
- isc_throw(InvalidRdataLength, "SSHFP record too short");
+ isc_throw(InvalidRdataLength, "SSHFP record too short");
}
algorithm_ = buffer.readUint8();
fingerprint_type_ = buffer.readUint8();
+ if (algorithm_ < 1) {
+ isc_throw(InvalidRdataText, "SSHFP algorithm number out of range");
+ }
+
+ if (fingerprint_type_ < 1) {
+ isc_throw(InvalidRdataText, "SSHFP fingerprint type out of range");
+ }
+
rdata_len -= 2;
fingerprint_.resize(rdata_len);
buffer.readData(&fingerprint_[0], rdata_len);
@@ -57,27 +65,53 @@ SSHFP::SSHFP(const std::string& sshfp_str) {
iss >> algorithm >> fingerprint_type;
if (iss.bad() || iss.fail()) {
- isc_throw(InvalidRdataText, "Invalid SSHFP text");
+ isc_throw(InvalidRdataText, "Invalid SSHFP text");
+ }
+
+ if ((algorithm < 1) || (algorithm > 255)) {
+ isc_throw(InvalidRdataText, "SSHFP algorithm number out of range");
+ }
+
+ if ((fingerprint_type < 1) || (fingerprint_type > 255)) {
+ isc_throw(InvalidRdataText, "SSHFP fingerprint type out of range");
}
iss.read(&peekc, 1);
if (!iss.good() || !isspace(peekc, iss.getloc())) {
- isc_throw(InvalidRdataText, "SSHFP presentation format error");
+ isc_throw(InvalidRdataText, "SSHFP presentation format error");
}
iss >> &fingerprintbuf;
algorithm_ = algorithm;
fingerprint_type_ = fingerprint_type;
- decodeHex(fingerprintbuf.str(), fingerprint_);
+
+ try {
+ decodeHex(fingerprintbuf.str(), fingerprint_);
+ } catch (const isc::BadValue& e) {
+ isc_throw(InvalidRdataText, "Bad SSHFP fingerprint: " << e.what());
+ }
}
SSHFP::SSHFP(uint8_t algorithm, uint8_t fingerprint_type,
const std::string& fingerprint)
{
+ if (algorithm < 1) {
+ isc_throw(InvalidRdataText, "SSHFP algorithm number out of range");
+ }
+
+ if (fingerprint_type < 1) {
+ isc_throw(InvalidRdataText, "SSHFP fingerprint type out of range");
+ }
+
algorithm_ = algorithm;
fingerprint_type_ = fingerprint_type;
- decodeHex(fingerprint, fingerprint_);
+
+ try {
+ decodeHex(fingerprint, fingerprint_);
+ } catch (const isc::BadValue& e) {
+ isc_throw(InvalidRdataText, "Bad SSHFP fingerprint: " << e.what());
+ }
}
SSHFP::SSHFP(const SSHFP& other) :
@@ -131,10 +165,10 @@ SSHFP::compare(const Rdata& other) const {
size_t cmplen = min(this_len, other_len);
int cmp = memcmp(&fingerprint_[0], &other_sshfp.fingerprint_[0], cmplen);
if (cmp != 0) {
- return (cmp);
+ return (cmp);
} else {
- return ((this_len == other_len)
- ? 0 : (this_len < other_len) ? -1 : 1);
+ return ((this_len == other_len)
+ ? 0 : (this_len < other_len) ? -1 : 1);
}
}
diff --git a/src/lib/dns/tests/rdata_sshfp_unittest.cc b/src/lib/dns/tests/rdata_sshfp_unittest.cc
index 0e5b865..79d1d66 100644
--- a/src/lib/dns/tests/rdata_sshfp_unittest.cc
+++ b/src/lib/dns/tests/rdata_sshfp_unittest.cc
@@ -60,24 +60,35 @@ TEST_F(Rdata_SSHFP_Test, algorithmTypes) {
// Some of these may not be RFC conformant, but we relax the check
// in our code to work with algorithm and fingerprint types that may
// show up in the future.
- EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("0 1 123456789abcdef67890123456789abcdef67890"));
- EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("1 1 123456789abcdef67890123456789abcdef67890"));
- EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("2 1 123456789abcdef67890123456789abcdef67890"));
- EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("3 1 123456789abcdef67890123456789abcdef67890"));
- EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("128 1 123456789abcdef67890123456789abcdef67890"));
- EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("255 1 123456789abcdef67890123456789abcdef67890"));
- EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("1 1 123456789abcdef67890123456789abcdef67890"));
- EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("1 2 123456789abcdef67890123456789abcdef67890"));
- EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("1 3 123456789abcdef67890123456789abcdef67890"));
- EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("1 128 123456789abcdef67890123456789abcdef67890"));
- EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("1 255 123456789abcdef67890123456789abcdef67890"));
+ EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("1 1 12ab"));
+ EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("2 1 12ab"));
+ EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("3 1 12ab"));
+ EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("128 1 12ab"));
+ EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("255 1 12ab"));
+ EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("1 1 12ab"));
+ EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("1 2 12ab"));
+ EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("1 3 12ab"));
+ EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("1 128 12ab"));
+ EXPECT_NO_THROW(const generic::SSHFP rdata_sshfp("1 255 12ab"));
+
+ // 0 is still reserved.
+ EXPECT_THROW(const generic::SSHFP rdata_sshfp("0 1 12ab"),
+ InvalidRdataText);
+ EXPECT_THROW(const generic::SSHFP rdata_sshfp("1 0 12ab"),
+ InvalidRdataText);
+
+ // > 255 would be broken
+ EXPECT_THROW(const generic::SSHFP rdata_sshfp("256 1 12ab"),
+ InvalidRdataText);
+ EXPECT_THROW(const generic::SSHFP rdata_sshfp("2 256 12ab"),
+ InvalidRdataText);
}
TEST_F(Rdata_SSHFP_Test, badText) {
EXPECT_THROW(const generic::SSHFP rdata_sshfp("1"), InvalidRdataText);
EXPECT_THROW(const generic::SSHFP rdata_sshfp("1 2"), InvalidRdataText);
EXPECT_THROW(const generic::SSHFP rdata_sshfp("BUCKLE MY SHOES"), InvalidRdataText);
- EXPECT_THROW(const generic::SSHFP rdata_sshfp("1 2 foo bar"), isc::BadValue);
+ EXPECT_THROW(const generic::SSHFP rdata_sshfp("1 2 foo bar"), InvalidRdataText);
}
TEST_F(Rdata_SSHFP_Test, copy) {
@@ -94,7 +105,27 @@ TEST_F(Rdata_SSHFP_Test, createFromWire) {
EXPECT_EQ(0, rdata_sshfp.compare(
*rdataFactoryFromFile(RRType("SSHFP"), RRClass("IN"),
"rdata_sshfp_fromWire2")));
- // TBD: more tests
+ // algorithm=1, fingerprint=1
+ EXPECT_NO_THROW(rdataFactoryFromFile(RRType("SSHFP"), RRClass("IN"),
+ "rdata_sshfp_fromWire3.wire"));
+
+ // algorithm=255, fingerprint=1
+ EXPECT_NO_THROW(rdataFactoryFromFile(RRType("SSHFP"), RRClass("IN"),
+ "rdata_sshfp_fromWire4.wire"));
+
+ // algorithm=0, fingerprint=1
+ EXPECT_THROW(rdataFactoryFromFile(RRType("SSHFP"), RRClass("IN"),
+ "rdata_sshfp_fromWire5.wire"),
+ InvalidRdataText);
+
+ // algorithm=5, fingerprint=0
+ EXPECT_THROW(rdataFactoryFromFile(RRType("SSHFP"), RRClass("IN"),
+ "rdata_sshfp_fromWire6.wire"),
+ InvalidRdataText);
+
+ // algorithm=255, fingerprint=255
+ EXPECT_NO_THROW(rdataFactoryFromFile(RRType("SSHFP"), RRClass("IN"),
+ "rdata_sshfp_fromWire7.wire"));
}
TEST_F(Rdata_SSHFP_Test, toText) {
diff --git a/src/lib/dns/tests/testdata/.gitignore b/src/lib/dns/tests/testdata/.gitignore
index e56355b..5b217a8 100644
--- a/src/lib/dns/tests/testdata/.gitignore
+++ b/src/lib/dns/tests/testdata/.gitignore
@@ -79,6 +79,11 @@
/rdata_soa_toWireUncompressed.wire
/rdata_sshfp_fromWire1.wire
/rdata_sshfp_fromWire2.wire
+/rdata_sshfp_fromWire3.wire
+/rdata_sshfp_fromWire4.wire
+/rdata_sshfp_fromWire5.wire
+/rdata_sshfp_fromWire6.wire
+/rdata_sshfp_fromWire7.wire
/rdata_tsig_fromWire1.wire
/rdata_tsig_fromWire2.wire
/rdata_tsig_fromWire3.wire
diff --git a/src/lib/dns/tests/testdata/Makefile.am b/src/lib/dns/tests/testdata/Makefile.am
index 043ea55..d4f95fb 100644
--- a/src/lib/dns/tests/testdata/Makefile.am
+++ b/src/lib/dns/tests/testdata/Makefile.am
@@ -45,6 +45,9 @@ BUILT_SOURCES += rdata_rp_fromWire3.wire rdata_rp_fromWire4.wire
BUILT_SOURCES += rdata_rp_fromWire5.wire rdata_rp_fromWire6.wire
BUILT_SOURCES += rdata_rp_toWire1.wire rdata_rp_toWire2.wire
BUILT_SOURCES += rdata_sshfp_fromWire1.wire rdata_sshfp_fromWire2.wire
+BUILT_SOURCES += rdata_sshfp_fromWire3.wire rdata_sshfp_fromWire4.wire
+BUILT_SOURCES += rdata_sshfp_fromWire5.wire rdata_sshfp_fromWire6.wire
+BUILT_SOURCES += rdata_sshfp_fromWire7.wire
BUILT_SOURCES += rdata_afsdb_fromWire1.wire rdata_afsdb_fromWire2.wire
BUILT_SOURCES += rdata_afsdb_fromWire3.wire rdata_afsdb_fromWire4.wire
BUILT_SOURCES += rdata_afsdb_fromWire5.wire
@@ -129,6 +132,9 @@ EXTRA_DIST += rdata_rp_fromWire5.spec rdata_rp_fromWire6.spec
EXTRA_DIST += rdata_rp_toWire1.spec rdata_rp_toWire2.spec
EXTRA_DIST += rdata_sshfp_fromWire rdata_sshfp_fromWire2
EXTRA_DIST += rdata_sshfp_fromWire1.spec rdata_sshfp_fromWire2.spec
+EXTRA_DIST += rdata_sshfp_fromWire3.spec rdata_sshfp_fromWire4.spec
+EXTRA_DIST += rdata_sshfp_fromWire5.spec rdata_sshfp_fromWire6.spec
+EXTRA_DIST += rdata_sshfp_fromWire7.spec
EXTRA_DIST += rdata_afsdb_fromWire1.spec rdata_afsdb_fromWire2.spec
EXTRA_DIST += rdata_afsdb_fromWire3.spec rdata_afsdb_fromWire4.spec
EXTRA_DIST += rdata_afsdb_fromWire5.spec
diff --git a/src/lib/dns/tests/testdata/rdata_sshfp_fromWire3.spec b/src/lib/dns/tests/testdata/rdata_sshfp_fromWire3.spec
new file mode 100644
index 0000000..bf80ec4
--- /dev/null
+++ b/src/lib/dns/tests/testdata/rdata_sshfp_fromWire3.spec
@@ -0,0 +1,9 @@
+#
+# SSHFP RDATA
+#
+[custom]
+sections: sshfp
+[sshfp]
+fingerprint: 123456789abcdef67890123456789abcdef67890
+algorithm: 1
+fingerprint_type: 1
diff --git a/src/lib/dns/tests/testdata/rdata_sshfp_fromWire4.spec b/src/lib/dns/tests/testdata/rdata_sshfp_fromWire4.spec
new file mode 100644
index 0000000..965c746
--- /dev/null
+++ b/src/lib/dns/tests/testdata/rdata_sshfp_fromWire4.spec
@@ -0,0 +1,9 @@
+#
+# SSHFP RDATA
+#
+[custom]
+sections: sshfp
+[sshfp]
+fingerprint: 123456789abcdef67890123456789abcdef67890
+algorithm: 255
+fingerprint_type: 1
diff --git a/src/lib/dns/tests/testdata/rdata_sshfp_fromWire5.spec b/src/lib/dns/tests/testdata/rdata_sshfp_fromWire5.spec
new file mode 100644
index 0000000..1aff335
--- /dev/null
+++ b/src/lib/dns/tests/testdata/rdata_sshfp_fromWire5.spec
@@ -0,0 +1,9 @@
+#
+# SSHFP RDATA
+#
+[custom]
+sections: sshfp
+[sshfp]
+fingerprint: 123456789abcdef67890123456789abcdef67890
+algorithm: 0
+fingerprint_type: 1
diff --git a/src/lib/dns/tests/testdata/rdata_sshfp_fromWire6.spec b/src/lib/dns/tests/testdata/rdata_sshfp_fromWire6.spec
new file mode 100644
index 0000000..f71d155
--- /dev/null
+++ b/src/lib/dns/tests/testdata/rdata_sshfp_fromWire6.spec
@@ -0,0 +1,9 @@
+#
+# SSHFP RDATA
+#
+[custom]
+sections: sshfp
+[sshfp]
+fingerprint: 123456789abcdef67890123456789abcdef67890
+algorithm: 5
+fingerprint_type: 0
diff --git a/src/lib/dns/tests/testdata/rdata_sshfp_fromWire7.spec b/src/lib/dns/tests/testdata/rdata_sshfp_fromWire7.spec
new file mode 100644
index 0000000..6fc63e9
--- /dev/null
+++ b/src/lib/dns/tests/testdata/rdata_sshfp_fromWire7.spec
@@ -0,0 +1,9 @@
+#
+# SSHFP RDATA
+#
+[custom]
+sections: sshfp
+[sshfp]
+fingerprint: 123456789abcdef67890123456789abcdef67890
+algorithm: 255
+fingerprint_type: 255
More information about the bind10-changes
mailing list