[Python-checkins] cpython (2.7): Issue #24257: Fixed segmentation fault in sqlite3.Row constructor with faked
serhiy.storchaka
python-checkins at python.org
Fri May 22 10:14:03 CEST 2015
https://hg.python.org/cpython/rev/bccaba8a5482
changeset: 96203:bccaba8a5482
branch: 2.7
parent: 96201:a4cb9c30cd91
user: Serhiy Storchaka <storchaka at gmail.com>
date: Fri May 22 11:00:40 2015 +0300
summary:
Issue #24257: Fixed segmentation fault in sqlite3.Row constructor with faked
cursor type.
files:
Lib/sqlite3/test/factory.py | 8 ++++++++
Misc/NEWS | 3 +++
Modules/_sqlite/row.c | 2 +-
3 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/Lib/sqlite3/test/factory.py b/Lib/sqlite3/test/factory.py
--- a/Lib/sqlite3/test/factory.py
+++ b/Lib/sqlite3/test/factory.py
@@ -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 --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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 --git a/Modules/_sqlite/row.c b/Modules/_sqlite/row.c
--- a/Modules/_sqlite/row.c
+++ b/Modules/_sqlite/row.c
@@ -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;
}
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list