Skip to content

Commit d02ac25

Browse files
authored
bpo-33136: Harden ssl module against CVE-2018-8970 (GH-6229)
Harden ssl module against LibreSSL CVE-2018-8970. X509_VERIFY_PARAM_set1_host() is called with an explicit namelen. A new test ensures that NULL bytes are not allowed. Signed-off-by: Christian Heimes <[email protected]>
1 parent e4ce9fa commit d02ac25

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

Lib/test/test_ssl.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,9 @@ def test_bad_server_hostname(self):
16601660
with self.assertRaises(ValueError):
16611661
ctx.wrap_bio(ssl.MemoryBIO(), ssl.MemoryBIO(),
16621662
server_hostname=".example.org")
1663+
with self.assertRaises(TypeError):
1664+
ctx.wrap_bio(ssl.MemoryBIO(), ssl.MemoryBIO(),
1665+
server_hostname="example.org\x00evil.com")
16631666

16641667

16651668
class MemoryBIOTests(unittest.TestCase):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Harden ssl module against LibreSSL CVE-2018-8970.
2+
X509_VERIFY_PARAM_set1_host() is called with an explicit namelen. A new test
3+
ensures that NULL bytes are not allowed.

Modules/_ssl.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,8 @@ _ssl_configure_hostname(PySSLSocket *self, const char* server_hostname)
852852
if (self->ctx->check_hostname) {
853853
X509_VERIFY_PARAM *param = SSL_get0_param(self->ssl);
854854
if (ip == NULL) {
855-
if (!X509_VERIFY_PARAM_set1_host(param, server_hostname, 0)) {
855+
if (!X509_VERIFY_PARAM_set1_host(param, server_hostname,
856+
strlen(server_hostname))) {
856857
_setSSLError(NULL, 0, __FILE__, __LINE__);
857858
goto error;
858859
}
@@ -4025,7 +4026,7 @@ _ssl__SSLContext__wrap_socket_impl(PySSLContext *self, PyObject *sock,
40254026
PyObject *res;
40264027

40274028
/* server_hostname is either None (or absent), or to be encoded
4028-
as IDN A-label (ASCII str). */
4029+
as IDN A-label (ASCII str) without NULL bytes. */
40294030
if (hostname_obj != Py_None) {
40304031
if (!PyArg_Parse(hostname_obj, "es", "ascii", &hostname))
40314032
return NULL;
@@ -4063,7 +4064,7 @@ _ssl__SSLContext__wrap_bio_impl(PySSLContext *self, PySSLMemoryBIO *incoming,
40634064
PyObject *res;
40644065

40654066
/* server_hostname is either None (or absent), or to be encoded
4066-
as IDN A-label (ASCII str). */
4067+
as IDN A-label (ASCII str) without NULL bytes. */
40674068
if (hostname_obj != Py_None) {
40684069
if (!PyArg_Parse(hostname_obj, "es", "ascii", &hostname))
40694070
return NULL;

0 commit comments

Comments
 (0)