Skip to content

Commit 66e2b4a

Browse files
miss-islingtondavidbenpicnixz
authored
[3.13] gh-141801: Use accessors for ASN1_STRING fields in libssl (GH-141802) (#141848)
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 * 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 616117b commit 66e2b4a

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
@@ -1361,14 +1361,14 @@ _get_peer_alt_names (_sslmodulestate *state, X509 *certificate) {
13611361
}
13621362
PyTuple_SET_ITEM(t, 0, v);
13631363

1364-
if (name->d.ip->length == 4) {
1365-
unsigned char *p = name->d.ip->data;
1364+
if (ASN1_STRING_length(name->d.ip) == 4) {
1365+
const unsigned char *p = ASN1_STRING_get0_data(name->d.ip);
13661366
v = PyUnicode_FromFormat(
13671367
"%d.%d.%d.%d",
13681368
p[0], p[1], p[2], p[3]
13691369
);
1370-
} else if (name->d.ip->length == 16) {
1371-
unsigned char *p = name->d.ip->data;
1370+
} else if (ASN1_STRING_length(name->d.ip) == 16) {
1371+
const unsigned char *p = ASN1_STRING_get0_data(name->d.ip);
13721372
v = PyUnicode_FromFormat(
13731373
"%X:%X:%X:%X:%X:%X:%X:%X",
13741374
p[0] << 8 | p[1],
@@ -1499,8 +1499,9 @@ _get_aia_uri(X509 *certificate, int nid) {
14991499
continue;
15001500
}
15011501
uri = ad->location->d.uniformResourceIdentifier;
1502-
ostr = PyUnicode_FromStringAndSize((char *)uri->data,
1503-
uri->length);
1502+
ostr = PyUnicode_FromStringAndSize(
1503+
(const char *)ASN1_STRING_get0_data(uri),
1504+
ASN1_STRING_length(uri));
15041505
if (ostr == NULL) {
15051506
goto fail;
15061507
}
@@ -1566,8 +1567,9 @@ _get_crl_dp(X509 *certificate) {
15661567
continue;
15671568
}
15681569
uri = gn->d.uniformResourceIdentifier;
1569-
ouri = PyUnicode_FromStringAndSize((char *)uri->data,
1570-
uri->length);
1570+
ouri = PyUnicode_FromStringAndSize(
1571+
(const char *)ASN1_STRING_get0_data(uri),
1572+
ASN1_STRING_length(uri));
15711573
if (ouri == NULL)
15721574
goto done;
15731575

0 commit comments

Comments
 (0)