Skip to content

Commit c41fce0

Browse files
davidbenpicnixz
andauthored
gh-141801: Use accessors for ASN1_STRING fields in libssl (GH-141802)
* gh-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 Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> * Update Modules/_ssl.c Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --------- Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent 5c25bc5 commit c41fce0

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
@@ -1437,14 +1437,14 @@ _get_peer_alt_names (_sslmodulestate *state, X509 *certificate) {
14371437
}
14381438
PyTuple_SET_ITEM(t, 0, v);
14391439

1440-
if (name->d.ip->length == 4) {
1441-
unsigned char *p = name->d.ip->data;
1440+
if (ASN1_STRING_length(name->d.ip) == 4) {
1441+
const unsigned char *p = ASN1_STRING_get0_data(name->d.ip);
14421442
v = PyUnicode_FromFormat(
14431443
"%d.%d.%d.%d",
14441444
p[0], p[1], p[2], p[3]
14451445
);
1446-
} else if (name->d.ip->length == 16) {
1447-
unsigned char *p = name->d.ip->data;
1446+
} else if (ASN1_STRING_length(name->d.ip) == 16) {
1447+
const unsigned char *p = ASN1_STRING_get0_data(name->d.ip);
14481448
v = PyUnicode_FromFormat(
14491449
"%X:%X:%X:%X:%X:%X:%X:%X",
14501450
p[0] << 8 | p[1],
@@ -1575,8 +1575,9 @@ _get_aia_uri(X509 *certificate, int nid) {
15751575
continue;
15761576
}
15771577
uri = ad->location->d.uniformResourceIdentifier;
1578-
ostr = PyUnicode_FromStringAndSize((char *)uri->data,
1579-
uri->length);
1578+
ostr = PyUnicode_FromStringAndSize(
1579+
(const char *)ASN1_STRING_get0_data(uri),
1580+
ASN1_STRING_length(uri));
15801581
if (ostr == NULL) {
15811582
goto fail;
15821583
}
@@ -1642,8 +1643,9 @@ _get_crl_dp(X509 *certificate) {
16421643
continue;
16431644
}
16441645
uri = gn->d.uniformResourceIdentifier;
1645-
ouri = PyUnicode_FromStringAndSize((char *)uri->data,
1646-
uri->length);
1646+
ouri = PyUnicode_FromStringAndSize(
1647+
(const char *)ASN1_STRING_get0_data(uri),
1648+
ASN1_STRING_length(uri));
16471649
if (ouri == NULL)
16481650
goto done;
16491651

0 commit comments

Comments
 (0)