set actual LeaseSet2 buffer size

This commit is contained in:
orignal 2020-03-20 17:43:37 -04:00
parent 168da33d8b
commit 962c2160c7
2 changed files with 16 additions and 0 deletions

View File

@ -251,6 +251,13 @@ namespace data
memcpy (m_Buffer, buf, len);
}
void LeaseSet::SetBufferLen (size_t len)
{
if (len <= m_BufferLen) m_BufferLen = len;
else
LogPrint (eLogError, "LeaseSet2: actual buffer size ", len , " exceeds full buffer size ", m_BufferLen);
}
LeaseSet2::LeaseSet2 (uint8_t storeType, const uint8_t * buf, size_t len, bool storeLeases, CryptoKeyType preferredCrypto):
LeaseSet (storeLeases), m_StoreType (storeType), m_EncryptionType (preferredCrypto)
{
@ -331,6 +338,8 @@ namespace data
VerifySignature (identity, buf, len, offset);
SetIsValid (verified);
}
offset += m_TransientVerifier ? m_TransientVerifier->GetSignatureLen () : identity->GetSignatureLen ();
SetBufferLen (offset);
}
template<typename Verifier>
@ -537,6 +546,12 @@ namespace data
else
LogPrint (eLogError, "LeaseSet2: unexpected LeaseSet type ", (int)innerPlainText[0], " inside encrypted LeaseSet");
}
else
{
// we set actual length of encrypted buffer
offset += m_TransientVerifier ? m_TransientVerifier->GetSignatureLen () : blindedVerifier->GetSignatureLen ();
SetBufferLen (offset);
}
}
// helper for ExtractClientAuthData

View File

@ -97,6 +97,7 @@ namespace data
// called from LeaseSet2
LeaseSet (bool storeLeases);
void SetBuffer (const uint8_t * buf, size_t len);
void SetBufferLen (size_t len);
void SetIdentity (std::shared_ptr<const IdentityEx> identity) { m_Identity = identity; };
void SetExpirationTime (uint64_t t) { m_ExpirationTime = t; };
void SetIsValid (bool isValid) { m_IsValid = isValid; };