bpo-35504: Fix segfaults and SystemErrors when deleting certain attrs. (GH-11175)
(cherry picked from commit 842acaab1376c5c84fd5966bb6070e289880e1ca)
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 9d0d9ca..49b545c 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -3049,6 +3049,10 @@
{
Py_ssize_t n;
CHECK_ATTACHED_INT(self);
+ if (arg == NULL) {
+ PyErr_SetString(PyExc_AttributeError, "cannot delete attribute");
+ return -1;
+ }
n = PyNumber_AsSsize_t(arg, PyExc_ValueError);
if (n == -1 && PyErr_Occurred())
return -1;