Skip to content

Commit 8a1649e

Browse files
Merge commit '1381d5ebd2ab1f292848d5b19b80cf71ac332508' into internal-merge-8.0-2024-02-13-1022
2 parents 3de24ef + 1381d5e commit 8a1649e

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

src/libraries/System.Security.Cryptography/tests/X509Certificates/CertTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,12 @@ public static void UseAfterDispose()
591591
}
592592
}
593593

594+
[Fact]
595+
public static void EmptyPkcs7ThrowsException()
596+
{
597+
Assert.ThrowsAny<CryptographicException>(() => new X509Certificate2(TestData.EmptyPkcs7));
598+
}
599+
594600
[Fact]
595601
public static void ExportPublicKeyAsPkcs12()
596602
{

src/libraries/System.Security.Cryptography/tests/X509Certificates/TestData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4273,5 +4273,7 @@ internal static DSAParameters GetDSA1024Params()
42734273
"C0CC2B115B9D33BD6E528E35670E5A6A8D9CF52199F8D693315C60D9ADAD54EF7FDCED36" +
42744274
"0C8C79E84D42AB5CB6355A70951B1ABF1F2B3FB8BEB7E3A8D6BA2293C0DB8C86B0BB060F" +
42754275
"0D6DB9939E88B998662A27F092634BBF21F58EEAAA").HexToByteArray();
4276+
4277+
internal static readonly byte[] EmptyPkcs7 = "300B06092A864886F70D010702".HexToByteArray();
42764278
}
42774279
}

src/native/libs/System.Security.Cryptography.Native/apibridge.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ int32_t local_X509_get_version(const X509* x509)
112112

113113
X509_PUBKEY* local_X509_get_X509_PUBKEY(const X509* x509)
114114
{
115-
if (x509)
115+
if (x509 && x509->cert_info)
116116
{
117117
return x509->cert_info->key;
118118
}
@@ -123,13 +123,28 @@ X509_PUBKEY* local_X509_get_X509_PUBKEY(const X509* x509)
123123
int32_t local_X509_PUBKEY_get0_param(
124124
ASN1_OBJECT** palgOid, const uint8_t** pkeyBytes, int* pkeyBytesLen, X509_ALGOR** palg, X509_PUBKEY* pubkey)
125125
{
126+
if (!pubkey)
127+
{
128+
return 0;
129+
}
130+
126131
if (palgOid)
127132
{
133+
if (!pubkey->algor)
134+
{
135+
return 0;
136+
}
137+
128138
*palgOid = pubkey->algor->algorithm;
129139
}
130140

131141
if (pkeyBytes)
132142
{
143+
if (!pubkey->public_key)
144+
{
145+
return 0;
146+
}
147+
133148
*pkeyBytes = pubkey->public_key->data;
134149
*pkeyBytesLen = pubkey->public_key->length;
135150
}

src/native/libs/System.Security.Cryptography.Native/openssl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,11 @@ BIO* CryptoNative_GetX509NameInfo(X509* x509, int32_t nameType, int32_t forIssue
669669
0 == strncmp(localOid, szOidUpn, sizeof(szOidUpn)))
670670
{
671671
// OTHERNAME->ASN1_TYPE->union.field
672+
if (!value->value)
673+
{
674+
return NULL;
675+
}
676+
672677
str = value->value->value.asn1_string;
673678
}
674679
}

src/native/libs/System.Security.Cryptography.Native/pal_pkcs7.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,19 @@ int32_t CryptoNative_GetPkcs7Certificates(PKCS7* p7, X509Stack** certs)
5353
switch (OBJ_obj2nid(p7->type))
5454
{
5555
case NID_pkcs7_signed:
56+
if (!p7->d.sign)
57+
{
58+
return 0;
59+
}
60+
5661
*certs = p7->d.sign->cert;
5762
return 1;
5863
case NID_pkcs7_signedAndEnveloped:
64+
if (!p7->d.signed_and_enveloped)
65+
{
66+
return 0;
67+
}
68+
5969
*certs = p7->d.signed_and_enveloped->cert;
6070
return 1;
6171
}

0 commit comments

Comments
 (0)