Skip to content

Commit 596214e

Browse files
Stop using ERR_GET_FUNC, since it has been removed in OSSL3 Beta2. (#57879)
Co-authored-by: Jeremy Barton <[email protected]>
1 parent 895eb99 commit 596214e

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/libraries/Native/Unix/System.Security.Cryptography.Native/openssl.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,27 +1068,30 @@ int32_t CryptoNative_LookupFriendlyNameByOid(const char* oidValue, const char**
10681068
return -2;
10691069
}
10701070

1071+
// First, check if oidValue parses as a dotted decimal OID. If not, we'll
1072+
// return not-found and let the system cache that.
1073+
int asnRet = a2d_ASN1_OBJECT(NULL, 0, oidValue, -1);
1074+
1075+
if (asnRet <= 0)
1076+
{
1077+
return 0;
1078+
}
1079+
10711080
// Do a lookup with no_name set. The purpose of this function is to map only the
10721081
// dotted decimal to the friendly name. "sha1" in should not result in "sha1" out.
10731082
oid = OBJ_txt2obj(oidValue, 1);
10741083

1075-
if (!oid)
1084+
if (oid == NULL)
10761085
{
1077-
unsigned long err = ERR_peek_last_error();
1078-
1079-
// If the most recent error pushed onto the error queue is NOT from OID parsing
1080-
// then signal for an exception to be thrown.
1081-
if (err != 0 && ERR_GET_FUNC(err) != ASN1_F_A2D_ASN1_OBJECT)
1082-
{
1083-
return -1;
1084-
}
1085-
1086-
return 0;
1086+
// We know that the OID parsed (unless it underwent concurrent modification,
1087+
// which is unsupported), so any error in this stage should be an exception.
1088+
return -1;
10871089
}
10881090

10891091
// Look in the predefined, and late-registered, OIDs list to get the lookup table
10901092
// identifier for this OID. The OBJ_txt2obj object will not have ln set.
10911093
nid = OBJ_obj2nid(oid);
1094+
ASN1_OBJECT_free(oid);
10921095

10931096
if (nid == NID_undef)
10941097
{

src/libraries/Native/Unix/System.Security.Cryptography.Native/opensslshim.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ const EVP_CIPHER* EVP_chacha20_poly1305(void);
159159
// that needs to be added.
160160

161161
#define FOR_ALL_OPENSSL_FUNCTIONS \
162+
REQUIRED_FUNCTION(a2d_ASN1_OBJECT) \
162163
REQUIRED_FUNCTION(ASN1_BIT_STRING_free) \
163164
REQUIRED_FUNCTION(ASN1_d2i_bio) \
164165
REQUIRED_FUNCTION(ASN1_i2d_bio) \
@@ -607,6 +608,7 @@ FOR_ALL_OPENSSL_FUNCTIONS
607608

608609
// Redefine all calls to OpenSSL functions as calls through pointers that are set
609610
// to the functions from the libssl.so selected by the shim.
611+
#define a2d_ASN1_OBJECT a2d_ASN1_OBJECT_ptr
610612
#define ASN1_BIT_STRING_free ASN1_BIT_STRING_free_ptr
611613
#define ASN1_GENERALIZEDTIME_free ASN1_GENERALIZEDTIME_free_ptr
612614
#define ASN1_d2i_bio ASN1_d2i_bio_ptr

0 commit comments

Comments
 (0)