]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-35504: Fix segfaults and SystemErrors when deleting certain attrs. (GH-11175)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 17 Dec 2018 15:10:20 +0000 (07:10 -0800)
committerGitHub <noreply@github.com>
Mon, 17 Dec 2018 15:10:20 +0000 (07:10 -0800)
(cherry picked from commit 842acaab1376c5c84fd5966bb6070e289880e1ca)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
15 files changed:
Lib/ctypes/test/test_strings.py
Lib/sqlite3/test/regression.py
Lib/test/multibytecodec_support.py
Lib/test/test_asyncio/test_futures.py
Lib/test/test_asyncio/test_tasks.py
Lib/test/test_frame.py
Lib/test/test_io.py
Misc/NEWS.d/next/Core and Builtins/2018-12-15-14-01-45.bpo-35504.JtKczP.rst [new file with mode: 0644]
Modules/_asynciomodule.c
Modules/_ctypes/_ctypes.c
Modules/_io/textio.c
Modules/_sqlite/connection.c
Modules/_ssl.c
Modules/cjkcodecs/multibytecodec.c
Objects/frameobject.c

index e28e141394de8abc78f3fa7906ff878518142754..5434efda10c0572dd09de128eb880bf05be58ba0 100644 (file)
@@ -54,6 +54,13 @@ class StringArrayTestCase(unittest.TestCase):
 ##        print BUF.from_param(c_char_p("python"))
 ##        print BUF.from_param(BUF(*"pyth"))
 
+    def test_del_segfault(self):
+        BUF = c_char * 4
+        buf = BUF()
+        with self.assertRaises(AttributeError):
+            del buf.raw
+
+
 @need_symbol('c_wchar')
 class WStringArrayTestCase(unittest.TestCase):
     def test(self):
index 1c59a3cd31c625834a4dda5e282d86828bf888fc..865bd88f74f10a4947f7338b328d8fb372a316d0 100644 (file)
@@ -379,6 +379,10 @@ class RegressionTests(unittest.TestCase):
         del ref
         support.gc_collect()
 
+    def CheckDelIsolation_levelSegfault(self):
+        with self.assertRaises(AttributeError):
+            del self.con.isolation_level
+
 
 class UnhashableFunc:
     __hash__ = None
index 813b7aa1bd2dd88b47e3edd418e0a9eea937cb7c..cca8af67d6d1d6cc65f586517981b3a04aaf865d 100644 (file)
@@ -277,6 +277,11 @@ class TestBase:
         writer = self.writer(stream)
         writer.reset()
 
+    def test_incrementalencoder_del_segfault(self):
+        e = self.incrementalencoder()
+        with self.assertRaises(AttributeError):
+            del e.errors
+
 
 class TestBase_Mapping(unittest.TestCase):
     pass_enctest = []
index 8c837ad6b620b6380d4c5ca06494b68f9bc1882d..9608a3a81cc334fc01635668822bdc0afa046265 100644 (file)
@@ -566,6 +566,13 @@ class CFutureTests(BaseFutureTests, test_utils.TestCase):
     except AttributeError:
         cls = None
 
+    def test_future_del_segfault(self):
+        fut = self._new_future(loop=self.loop)
+        with self.assertRaises(AttributeError):
+            del fut._asyncio_future_blocking
+        with self.assertRaises(AttributeError):
+            del fut._log_traceback
+
 
 @unittest.skipUnless(hasattr(futures, '_CFuture'),
                      'requires the C _asyncio module')
index 12c6ef4f619ebc3d50f3980844ea314c49c556f5..d92ed32bc99f606f7af656912c251dd1b37e25f2 100644 (file)
@@ -2512,6 +2512,15 @@ class CTask_CFuture_Tests(BaseTaskTests, SetMethodsTest,
             self.loop.run_until_complete(task)
         self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
 
+    def test_del__log_destroy_pending_segfault(self):
+        @asyncio.coroutine
+        def coro():
+            pass
+        task = self.new_task(self.loop, coro())
+        self.loop.run_until_complete(task)
+        with self.assertRaises(AttributeError):
+            del task._log_destroy_pending
+
 
 @unittest.skipUnless(hasattr(futures, '_CFuture') and
                      hasattr(tasks, '_CTask'),
index fd795085a5cd400e9fda91facd355166904e0053..d6aa2834cbc28b749b32f7daa412be296d5f68ca 100644 (file)
@@ -109,10 +109,7 @@ class ClearTest(unittest.TestCase):
             self.assertIs(None, wr())
 
 
-class FrameLocalsTest(unittest.TestCase):
-    """
-    Tests for the .f_locals attribute.
-    """
+class FrameAttrsTest(unittest.TestCase):
 
     def make_frames(self):
         def outer():
@@ -159,6 +156,11 @@ class FrameLocalsTest(unittest.TestCase):
         self.assertEqual(outer.f_locals, {})
         self.assertEqual(inner.f_locals, {})
 
+    def test_f_lineno_del_segfault(self):
+        f, _, _ = self.make_frames()
+        with self.assertRaises(AttributeError):
+            del f.f_lineno
+
 
 class ReprTest(unittest.TestCase):
     """
index b41141e28adbad31ef0a1b118546f0c93d063966..4c206d287f27dbb544494bc5adef577c9c80cb9e 100644 (file)
@@ -3635,6 +3635,11 @@ class CTextIOWrapperTest(TextIOWrapperTest):
             t2.buddy = t1
         support.gc_collect()
 
+    def test_del__CHUNK_SIZE_SystemError(self):
+        t = self.TextIOWrapper(self.BytesIO(), encoding='ascii')
+        with self.assertRaises(AttributeError):
+            del t._CHUNK_SIZE
+
 
 class PyTextIOWrapperTest(TextIOWrapperTest):
     io = pyio
diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-12-15-14-01-45.bpo-35504.JtKczP.rst b/Misc/NEWS.d/next/Core and Builtins/2018-12-15-14-01-45.bpo-35504.JtKczP.rst
new file mode 100644 (file)
index 0000000..2a4f0f6
--- /dev/null
@@ -0,0 +1,2 @@
+Fix segfaults and :exc:`SystemError`\ s when deleting certain attributes.
+Patch by Zackery Spytz.
index 5816a6748f66a3e35b3069f64d2e3ca9381ffd6e..35264f5815c3bce2ca37d184134f2e249a1ca433 100644 (file)
@@ -1110,6 +1110,10 @@ FutureObj_set_blocking(FutureObj *fut, PyObject *val, void *Py_UNUSED(ignored))
     if (future_ensure_alive(fut)) {
         return -1;
     }
+    if (val == NULL) {
+        PyErr_SetString(PyExc_AttributeError, "cannot delete attribute");
+        return -1;
+    }
 
     int is_true = PyObject_IsTrue(val);
     if (is_true < 0) {
@@ -1134,6 +1138,10 @@ FutureObj_get_log_traceback(FutureObj *fut, void *Py_UNUSED(ignored))
 static int
 FutureObj_set_log_traceback(FutureObj *fut, PyObject *val, void *Py_UNUSED(ignored))
 {
+    if (val == NULL) {
+        PyErr_SetString(PyExc_AttributeError, "cannot delete attribute");
+        return -1;
+    }
     int is_true = PyObject_IsTrue(val);
     if (is_true < 0) {
         return -1;
@@ -2008,6 +2016,10 @@ TaskObj_get_log_destroy_pending(TaskObj *task, void *Py_UNUSED(ignored))
 static int
 TaskObj_set_log_destroy_pending(TaskObj *task, PyObject *val, void *Py_UNUSED(ignored))
 {
+    if (val == NULL) {
+        PyErr_SetString(PyExc_AttributeError, "cannot delete attribute");
+        return -1;
+    }
     int is_true = PyObject_IsTrue(val);
     if (is_true < 0) {
         return -1;
index c5fc811ad98e34cb88e5f20a36be81e3be2e1227..937375a4ea44275b95b239504b1d1f58ad6cce8b 100644 (file)
@@ -1171,6 +1171,10 @@ CharArray_set_raw(CDataObject *self, PyObject *value, void *Py_UNUSED(ignored))
     Py_ssize_t size;
     Py_buffer view;
 
+    if (value == NULL) {
+        PyErr_SetString(PyExc_AttributeError, "cannot delete attribute");
+        return -1;
+    }
     if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0)
         return -1;
     size = view.len;
index 9d0d9cac40dbcc5ead13d8c442c0dff45af7c060..49b545c4787fbf8158131a51258b7c0bfb4ceb35 100644 (file)
@@ -3049,6 +3049,10 @@ textiowrapper_chunk_size_set(textio *self, PyObject *arg, void *context)
 {
     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;
index 351317e78db4fc285995a981b33799ad980e41e7..d43286a2d34d62f4f8b1dec90caa9fceb6e4e7a8 100644 (file)
@@ -1138,6 +1138,10 @@ static PyObject* pysqlite_connection_get_in_transaction(pysqlite_Connection* sel
 static int
 pysqlite_connection_set_isolation_level(pysqlite_Connection* self, PyObject* isolation_level, void *Py_UNUSED(ignored))
 {
+    if (isolation_level == NULL) {
+        PyErr_SetString(PyExc_AttributeError, "cannot delete attribute");
+        return -1;
+    }
     if (isolation_level == Py_None) {
         PyObject *res = pysqlite_connection_commit(self, NULL);
         if (!res) {
index 310b38bf11f4578e23cfdf3d5c27cca6c39c5650..9894ad821d63e8c3e81843ec2ca4c0d863b1a515 100644 (file)
@@ -3626,6 +3626,10 @@ static int
 set_post_handshake_auth(PySSLContext *self, PyObject *arg, void *c) {
     int (*verify_cb)(int, X509_STORE_CTX *) = NULL;
     int mode = SSL_CTX_get_verify_mode(self->ctx);
+    if (arg == NULL) {
+        PyErr_SetString(PyExc_AttributeError, "cannot delete attribute");
+        return -1;
+    }
     int pha = PyObject_IsTrue(arg);
 
     if (pha == -1) {
index 4d0aaf3a336f9ca9a5797eaf44eb2e898ec8570c..5c91ada103d5a08e979bfce6ab5f48d3502a31db 100644 (file)
@@ -133,6 +133,10 @@ codecctx_errors_set(MultibyteStatefulCodecContext *self, PyObject *value,
     PyObject *cb;
     const char *str;
 
+    if (value == NULL) {
+        PyErr_SetString(PyExc_AttributeError, "cannot delete attribute");
+        return -1;
+    }
     if (!PyUnicode_Check(value)) {
         PyErr_SetString(PyExc_TypeError, "errors must be a string");
         return -1;
index 4ef10d0eb7bcd6c4097f8029db11222f87fdff9d..4362615cb08986671c20a5540c20533403caf475 100644 (file)
@@ -90,6 +90,10 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore
     int blockstack_top = 0;             /* (ditto) */
     unsigned char setup_op = 0;         /* (ditto) */
 
+    if (p_new_lineno == NULL) {
+        PyErr_SetString(PyExc_AttributeError, "cannot delete attribute");
+        return -1;
+    }
     /* f_lineno must be an integer. */
     if (!PyLong_CheckExact(p_new_lineno)) {
         PyErr_SetString(PyExc_ValueError,