PcapPlusPlus icon indicating copy to clipboard operation
PcapPlusPlus copied to clipboard

Parse X509 certificates

Open seladb opened this issue 6 months ago • 3 comments

Prerequisite PRs:

  • https://github.com/seladb/PcapPlusPlus/pull/1836
  • https://github.com/seladb/PcapPlusPlus/pull/1837

seladb avatar May 30 '25 05:05 seladb

@seladb While looking for this issue, I went through this function in SSLHandshake.cpp

SSLx509Certificate* SSLCertificateMessage::getCertificate(int index) const
	{
		if (index < 0 || index > (int)m_CertificateList.size())
		{
			PCPP_LOG_DEBUG("certificate index out of range: asked for index " << index << ", total size is "
			                                                                  << m_CertificateList.size());
			return nullptr;
		}

		return const_cast<SSLx509Certificate*>(m_CertificateList.at(index));
	}

is the bound check correct here? if (index < 0 || index > (int)m_CertificateList.size())

It should be if (index < 0 || index >= (int)m_CertificateList.size()) ????

bhaskarbhar avatar May 31 '25 05:05 bhaskarbhar

@seladb While looking for this issue, I went through this function in SSLHandshake.cpp

SSLx509Certificate* SSLCertificateMessage::getCertificate(int index) const
	{
		if (index < 0 || index > (int)m_CertificateList.size())
		{
			PCPP_LOG_DEBUG("certificate index out of range: asked for index " << index << ", total size is "
			                                                                  << m_CertificateList.size());
			return nullptr;
		}

		return const_cast<SSLx509Certificate*>(m_CertificateList.at(index));
	}

is the bound check correct here? if (index < 0 || index > (int)m_CertificateList.size())

It should be if (index < 0 || index >= (int)m_CertificateList.size()) ????

Hmm yes, I think you're right, but I haven't tested it...

seladb avatar May 31 '25 07:05 seladb

@seladb I believe, using index > m_CertificateList.size() is incorrect because if index == m_CertificateList.size(), that index is out of bounds (since indexing is zero-based). Anyways not a big issue I guess.

bhaskarbhar avatar May 31 '25 08:05 bhaskarbhar