Issue #27861: Fixed a crash in sqlite3.Connection.cursor() when a factory

creates not a cursor.  Patch by Xiang Zhang.
This commit is contained in:
Serhiy Storchaka 2016-08-29 14:29:55 +03:00
parent 5de141f157
commit ef113cd4cc
4 changed files with 35 additions and 9 deletions

View file

@ -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);