Skip to content

Commit 972aa93

Browse files
miss-islingtondavidbenpicnixz
authored
[3.14] pythongh-141801: Use accessors for ASN1_STRING fields in libssl (pythonGH-141802) (python#141847)
pythongh-141801: Use accessors for ASN1_STRING fields in libssl (pythonGH-141802) * pythongh-141801: Use accessors for ASN1_STRING fields While ASN1_STRING is currently exposed, it is better to use the accessors. See openssl/openssl#29117 where, if the type were opaque, OpenSSL's X509 objects could be much more memory-efficient. * Update Modules/_ssl.c * Update Modules/_ssl.c --------- (cherry picked from commit c41fce0) Co-authored-by: David Benjamin <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
1 parent c9a4a3d commit 972aa93

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Modules/_ssl.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,14 +1410,14 @@ _get_peer_alt_names (_sslmodulestate *state, X509 *certificate) {
14101410
}
14111411
PyTuple_SET_ITEM(t, 0, v);
14121412

1413-
if (name->d.ip->length == 4) {
1414-
unsigned char *p = name->d.ip->data;
1413+
if (ASN1_STRING_length(name->d.ip) == 4) {
1414+
const unsigned char *p = ASN1_STRING_get0_data(name->d.ip);
14151415
v = PyUnicode_FromFormat(
14161416
"%d.%d.%d.%d",
14171417
p[0], p[1], p[2], p[3]
14181418
);
1419-
} else if (name->d.ip->length == 16) {
1420-
unsigned char *p = name->d.ip->data;
1419+
} else if (ASN1_STRING_length(name->d.ip) == 16) {
1420+
const unsigned char *p = ASN1_STRING_get0_data(name->d.ip);
14211421
v = PyUnicode_FromFormat(
14221422
"%X:%X:%X:%X:%X:%X:%X:%X",
14231423
p[0] << 8 | p[1],
@@ -1548,8 +1548,9 @@ _get_aia_uri(X509 *certificate, int nid) {
15481548
continue;
15491549
}
15501550
uri = ad->location->d.uniformResourceIdentifier;
1551-
ostr = PyUnicode_FromStringAndSize((char *)uri->data,
1552-
uri->length);
1551+
ostr = PyUnicode_FromStringAndSize(
1552+
(const char *)ASN1_STRING_get0_data(uri),
1553+
ASN1_STRING_length(uri));
15531554
if (ostr == NULL) {
15541555
goto fail;
15551556
}
@@ -1615,8 +1616,9 @@ _get_crl_dp(X509 *certificate) {
16151616
continue;
16161617
}
16171618
uri = gn->d.uniformResourceIdentifier;
1618-
ouri = PyUnicode_FromStringAndSize((char *)uri->data,
1619-
uri->length);
1619+
ouri = PyUnicode_FromStringAndSize(
1620+
(const char *)ASN1_STRING_get0_data(uri),
1621+
ASN1_STRING_length(uri));
16201622
if (ouri == NULL)
16211623
goto done;
16221624

0 commit comments

Comments
 (0)