cpython: c7b9645a6f35 (original) (raw)
Mercurial > cpython
changeset 96204:c7b9645a6f35 3.4
Issue #24257: Fixed incorrect uses of PyObject_IsInstance(). Fixed segmentation fault in sqlite3.Row constructor with faked cursor type. Fixed system error in the comparison of faked types.SimpleNamespace. [#24257]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Fri, 22 May 2015 11:02:49 +0300 |
parents | 16c42506fbdf |
children | a5101529a8a9 645a03e93008 |
files | Lib/sqlite3/test/factory.py Lib/test/test_types.py Misc/NEWS Modules/_sqlite/row.c Objects/genobject.c Objects/namespaceobject.c |
diffstat | 6 files changed, 36 insertions(+), 8 deletions(-)[+] [-] Lib/sqlite3/test/factory.py 8 Lib/test/test_types.py 16 Misc/NEWS 6 Modules/_sqlite/row.c 2 Objects/genobject.c 5 Objects/namespaceobject.c 7 |
line wrap: on
line diff
--- a/Lib/sqlite3/test/factory.py +++ b/Lib/sqlite3/test/factory.py @@ -162,6 +162,14 @@ class RowFactoryTests(unittest.TestCase) self.assertEqual(list(reversed(row)), list(reversed(as_tuple))) self.assertIsInstance(row, Sequence)
- def CheckFakeCursorClass(self):
# Issue #24257: Incorrect use of PyObject_IsInstance() caused[](#l1.8)
# segmentation fault.[](#l1.9)
class FakeCursor(str):[](#l1.10)
__class__ = sqlite.Cursor[](#l1.11)
cur = self.con.cursor(factory=FakeCursor)[](#l1.12)
self.assertRaises(TypeError, sqlite.Row, cur, ())[](#l1.13)
+ def tearDown(self): self.con.close()
--- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -1169,6 +1169,22 @@ class SimpleNamespaceTests(unittest.Test self.assertEqual(ns, ns_roundtrip, pname)
- def test_fake_namespace_compare(self):
# Issue #24257: Incorrect use of PyObject_IsInstance() caused[](#l2.8)
# SystemError.[](#l2.9)
class FakeSimpleNamespace(str):[](#l2.10)
__class__ = types.SimpleNamespace[](#l2.11)
self.assertFalse(types.SimpleNamespace() == FakeSimpleNamespace())[](#l2.12)
self.assertTrue(types.SimpleNamespace() != FakeSimpleNamespace())[](#l2.13)
with self.assertRaises(TypeError):[](#l2.14)
types.SimpleNamespace() < FakeSimpleNamespace()[](#l2.15)
with self.assertRaises(TypeError):[](#l2.16)
types.SimpleNamespace() <= FakeSimpleNamespace()[](#l2.17)
with self.assertRaises(TypeError):[](#l2.18)
types.SimpleNamespace() > FakeSimpleNamespace()[](#l2.19)
with self.assertRaises(TypeError):[](#l2.20)
types.SimpleNamespace() >= FakeSimpleNamespace()[](#l2.21)
+ def test_main(): run_unittest(TypesTests, MappingProxyTests, ClassCreationTests,
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Release date: tba Core and Builtins ----------------- +- Issue #24257: Fixed system error in the comparison of faked
- Issue #22939: Fixed integer overflow in iterator object. Patch by Clement Rouault. @@ -56,6 +59,9 @@ Core and Builtins Library ------- +- Issue #24257: Fixed segmentation fault in sqlite3.Row constructor with faked
- Issue #22107: tempfile.gettempdir() and tempfile.mkdtemp() now try again when a directory with the chosen name already exists on Windows as well as on Unix. tempfile.mkstemp() now fails early if parent directory is not
--- a/Modules/_sqlite/row.c +++ b/Modules/_sqlite/row.c @@ -46,7 +46,7 @@ pysqlite_row_new(PyTypeObject *type, PyO if (!PyArg_ParseTuple(args, "OO", &cursor, &data)) return NULL;
- if (!PyObject_TypeCheck((PyObject*)cursor, &pysqlite_CursorType)) { PyErr_SetString(PyExc_TypeError, "instance of cursor required for first argument"); return NULL; }
--- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -398,8 +398,7 @@ int PyErr_Fetch(&et, &ev, &tb); if (ev) { /* exception will usually be normalised already */
if (Py_TYPE(ev) == (PyTypeObject *) et[](#l5.7)
|| PyObject_IsInstance(ev, PyExc_StopIteration)) {[](#l5.8)
if (PyObject_TypeCheck(ev, (PyTypeObject *) et)) {[](#l5.9) value = ((PyStopIterationObject *)ev)->value;[](#l5.10) Py_INCREF(value);[](#l5.11) Py_DECREF(ev);[](#l5.12)
@@ -409,7 +408,7 @@ int } else { /* normalisation required */ PyErr_NormalizeException(&et, &ev, &tb);
if (!PyObject_IsInstance(ev, PyExc_StopIteration)) {[](#l5.17)
if (!PyObject_TypeCheck(ev, (PyTypeObject *)PyExc_StopIteration)) {[](#l5.18) PyErr_Restore(et, ev, tb);[](#l5.19) return -1;[](#l5.20) }[](#l5.21)
--- a/Objects/namespaceobject.c +++ b/Objects/namespaceobject.c @@ -164,12 +164,11 @@ namespace_clear(_PyNamespaceObject *ns) static PyObject * namespace_richcompare(PyObject *self, PyObject *other, int op) {
- if (PyObject_IsInstance(self, (PyObject *)&_PyNamespace_Type) &&
PyObject_IsInstance(other, (PyObject *)&_PyNamespace_Type))[](#l6.8)