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 "
}
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> >
// 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 "
// 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);
}
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
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());
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