File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments