changeset: 96203:bccaba8a5482 branch: 2.7 parent: 96201:a4cb9c30cd91 user: Serhiy Storchaka date: Fri May 22 11:00:40 2015 +0300 files: Lib/sqlite3/test/factory.py Misc/NEWS Modules/_sqlite/row.c description: Issue #24257: Fixed segmentation fault in sqlite3.Row constructor with faked cursor type. diff -r a4cb9c30cd91 -r bccaba8a5482 Lib/sqlite3/test/factory.py --- a/Lib/sqlite3/test/factory.py Fri May 22 00:43:31 2015 -0400 +++ b/Lib/sqlite3/test/factory.py Fri May 22 11:00:40 2015 +0300 @@ -170,6 +170,14 @@ self.assertEqual(list(reversed(row)), list(reversed(as_tuple))) self.assertIsInstance(row, Sequence) + def CheckFakeCursorClass(self): + # Issue #24257: Incorrect use of PyObject_IsInstance() caused + # segmentation fault. + class FakeCursor(str): + __class__ = sqlite.Cursor + cur = self.con.cursor(factory=FakeCursor) + self.assertRaises(TypeError, sqlite.Row, cur, ()) + def tearDown(self): self.con.close() diff -r a4cb9c30cd91 -r bccaba8a5482 Misc/NEWS --- a/Misc/NEWS Fri May 22 00:43:31 2015 -0400 +++ b/Misc/NEWS Fri May 22 11:00:40 2015 +0300 @@ -18,6 +18,9 @@ Library ------- +- Issue #24257: Fixed segmentation fault in sqlite3.Row constructor with faked + cursor type. + - 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 diff -r a4cb9c30cd91 -r bccaba8a5482 Modules/_sqlite/row.c --- a/Modules/_sqlite/row.c Fri May 22 00:43:31 2015 -0400 +++ b/Modules/_sqlite/row.c Fri May 22 11:00:40 2015 +0300 @@ -47,7 +47,7 @@ if (!PyArg_ParseTuple(args, "OO", &cursor, &data)) return NULL; - if (!PyObject_IsInstance((PyObject*)cursor, (PyObject*)&pysqlite_CursorType)) { + if (!PyObject_TypeCheck((PyObject*)cursor, &pysqlite_CursorType)) { PyErr_SetString(PyExc_TypeError, "instance of cursor required for first argument"); return NULL; }