Skip to content

Commit cf70a8d

Browse files
dergoeggevasild
andcommitted
[net] Check i2p private key constraints
Co-authored-by: Vasil Dimov <[email protected]>
1 parent 106ab20 commit cf70a8d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/i2p.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,26 @@ Binary Session::MyDestination() const
351351
static constexpr size_t CERT_LEN_POS = 385;
352352

353353
uint16_t cert_len;
354+
355+
if (m_private_key.size() < CERT_LEN_POS + sizeof(cert_len)) {
356+
throw std::runtime_error(strprintf("The private key is too short (%d < %d)",
357+
m_private_key.size(),
358+
CERT_LEN_POS + sizeof(cert_len)));
359+
}
360+
354361
memcpy(&cert_len, &m_private_key.at(CERT_LEN_POS), sizeof(cert_len));
355362
cert_len = be16toh(cert_len);
356363

357364
const size_t dest_len = DEST_LEN_BASE + cert_len;
358365

366+
if (dest_len > m_private_key.size()) {
367+
throw std::runtime_error(strprintf("Certificate length (%d) designates that the private key should "
368+
"be %d bytes, but it is only %d bytes",
369+
cert_len,
370+
dest_len,
371+
m_private_key.size()));
372+
}
373+
359374
return Binary{m_private_key.begin(), m_private_key.begin() + dest_len};
360375
}
361376

0 commit comments

Comments
 (0)