Skip to content

Commit 0a933bf

Browse files
committed
gh-160040: protect against accidental type change
Signed-off-by: Christian Heimes <christian@python.org>
1 parent c78d2e5 commit 0a933bf

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎Modules/_ssl.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3396,12 +3396,15 @@ _cert_has_distrusted_spki(X509 *cert)
33963396
int ok = EVP_Digest(spki, (size_t)spki_len, digest, &digest_len,
33973397
EVP_sha256(), NULL);
33983398
OPENSSL_free(spki);
3399-
if (!ok || digest_len != sizeof(_distrusted_spki[0])) {
3399+
assert(sizeof(_distrusted_spki[0]) == SHA256_DIGEST_LENGTH);
3400+
if (!ok
3401+
|| digest_len != SHA256_DIGEST_LENGTH
3402+
|| sizeof(_distrusted_spki[0]) != SHA256_DIGEST_LENGTH) {
34003403
return -1;
34013404
}
34023405

34033406
for (size_t i = 0; i < Py_ARRAY_LENGTH(_distrusted_spki); i++) {
3404-
if (memcmp(digest, _distrusted_spki[i], sizeof(_distrusted_spki[i])) == 0) {
3407+
if (memcmp(digest, _distrusted_spki[i], SHA256_DIGEST_LENGTH) == 0) {
34053408
return 1;
34063409
}
34073410
}

0 commit comments

Comments
 (0)