Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit dc76a2e

Browse files
committed
Fix SegFault due to calling X509_check_purpose after d2i_X509 failed.
CoreFX X509Certificates on Unix currently only support DER-encoded public certificates (".cer"). Any of the other binary constructor tests resulted in an invalid pointer, because d2i failed to decode.
1 parent 8d8d3bc commit dc76a2e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/OpenSslX509CertificateReader.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ internal unsafe OpenSslX509CertificateReader(byte[] data)
3030

3131
_cert = Interop.libcrypto.d2i_X509(IntPtr.Zero, ppData, data.Length);
3232

33+
if (_cert.IsInvalid)
34+
{
35+
throw new CryptographicException();
36+
}
37+
3338
// X509_check_purpose has the effect of populating the sha1_hash value,
3439
// and other "initialize" type things.
3540
bool init = Interop.libcrypto.X509_check_purpose(_cert, -1, 0);

0 commit comments

Comments
 (0)