signature: disallow encoding invalid SignatureInfo
Also, check integer range when decoding SignatureInfo.
refs #3200
Change-Id: I1af4833211c9468ac7ecab48f7d0e88e9423b378
diff --git a/src/signature-info.cpp b/src/signature-info.cpp
index 36964ac..0b3b0a1 100644
--- a/src/signature-info.cpp
+++ b/src/signature-info.cpp
@@ -60,6 +60,10 @@
size_t
SignatureInfo::wireEncode(EncodingImpl<TAG>& encoder) const
{
+ if (m_type == -1) {
+ BOOST_THROW_EXCEPTION(Error("Cannot encode invalid SignatureInfo"));
+ }
+
// SignatureInfo ::= SIGNATURE-INFO-TLV TLV-LENGTH
// SignatureType
// KeyLocator?
@@ -114,15 +118,15 @@
Block::element_const_iterator it = m_wire.elements_begin();
- // the first block must be SignatureType
+ // the first sub-element must be SignatureType
if (it != m_wire.elements_end() && it->type() == tlv::SignatureType) {
- m_type = readNonNegativeInteger(*it);
+ m_type = readNonNegativeIntegerAs<int32_t>(*it);
++it;
}
else
BOOST_THROW_EXCEPTION(Error("Missing SignatureType in SignatureInfo"));
- // the second block could be KeyLocator
+ // the second sub-element could be KeyLocator
if (it != m_wire.elements_end() && it->type() == tlv::KeyLocator) {
m_keyLocator.wireDecode(*it);
m_hasKeyLocator = true;