Skip to content

Commit de386f2

Browse files
[3.14] gh-156099: Fix a crash when deleting SSLContext.keylog_filename (GH-156103) (GH-156149)
The setter did not check the value for NULL and passed it to Py_fopen(). (cherry picked from commit 5ebd486)
1 parent 197fdd7 commit de386f2

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

Lib/test/test_ssl.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5184,6 +5184,12 @@ def test_keylog_defaults(self):
51845184
with self.assertRaises(TypeError):
51855185
ctx.keylog_filename = 1
51865186

5187+
ctx.keylog_filename = os_helper.TESTFN
5188+
with self.assertRaisesRegex(AttributeError, 'cannot be deleted'):
5189+
del ctx.keylog_filename
5190+
# a failed deletion does not change the value
5191+
self.assertEqual(ctx.keylog_filename, os_helper.TESTFN)
5192+
51875193
@requires_keylog
51885194
def test_keylog_filename(self):
51895195
self.addCleanup(os_helper.unlink, os_helper.TESTFN)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a crash when deleting the ``keylog_filename`` attribute of
2+
:class:`ssl.SSLContext`.
3+
It now raises :exc:`AttributeError`.

Modules/_ssl/debughelpers.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ _PySSLContext_set_keylog_filename(PyObject *op, PyObject *arg,
176176
PySSLContext *self = PySSLContext_CAST(op);
177177
FILE *fp;
178178

179+
if (arg == NULL) {
180+
PyErr_Format(PyExc_AttributeError,
181+
"attribute 'keylog_filename' of '%.100s' objects "
182+
"cannot be deleted", Py_TYPE(op)->tp_name);
183+
return -1;
184+
}
179185
#if defined(MS_WINDOWS) && defined(_DEBUG)
180186
PyErr_SetString(PyExc_NotImplementedError,
181187
"set_keylog_filename: unavailable on Windows debug build");

0 commit comments

Comments
 (0)