diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-08-29 11:29:55 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-08-29 11:29:55 (GMT) |
commit | ef113cd4cc2c16fa0ce59e325ee587698d62e1ae (patch) | |
tree | 0bbd4523aae926a7495471502c4a10a2590aeb9a /Modules | |
parent | 5de141f157ab372f5dd5b28c17442e41e15101af (diff) | |
download | cpython-ef113cd4cc2c16fa0ce59e325ee587698d62e1ae.zip cpython-ef113cd4cc2c16fa0ce59e325ee587698d62e1ae.tar.gz cpython-ef113cd4cc2c16fa0ce59e325ee587698d62e1ae.tar.bz2 |
Issue #27861: Fixed a crash in sqlite3.Connection.cursor() when a factory
creates not a cursor. Patch by Xiang Zhang.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_sqlite/connection.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index fcc1695..bea930d 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -300,7 +300,7 @@ error: PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args, PyObject* kwargs) { - static char *kwlist[] = {"factory", NULL, NULL}; + static char *kwlist[] = {"factory", NULL}; PyObject* factory = NULL; PyObject* cursor; @@ -317,7 +317,16 @@ PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args, factory = (PyObject*)&pysqlite_CursorType; } - cursor = PyObject_CallFunction(factory, "O", self); + cursor = PyObject_CallFunctionObjArgs(factory, (PyObject *)self, NULL); + if (cursor == NULL) + return NULL; + if (!PyObject_TypeCheck(cursor, &pysqlite_CursorType)) { + PyErr_Format(PyExc_TypeError, + "factory must return a cursor, not %.100s", + Py_TYPE(cursor)->tp_name); + Py_DECREF(cursor); + return NULL; + } _pysqlite_drop_unused_cursor_references(self); |