gh-149738: Fix segmentation fault bug in sqllite3 (#149754)

Deleting the `row_factory` or `text_factory` attribute is no longer allowed.
This commit is contained in:
Sepehr Rasouli 2026-06-02 12:37:08 +03:30 committed by GitHub
parent 5a2d2736a6
commit 60fdb3192b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 66 additions and 2 deletions

View file

@ -557,6 +557,47 @@ pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory)
return cursor;
}
static PyObject *
connection_get_row_factory(PyObject *op, void *closure)
{
pysqlite_Connection *self = (pysqlite_Connection *)op;
return Py_NewRef(self->row_factory);
}
static int
connection_set_row_factory(PyObject *op, PyObject *value, void *closure)
{
pysqlite_Connection *self = (pysqlite_Connection *)op;
if (value == NULL) {
PyErr_SetString(PyExc_AttributeError,
"cannot delete row_factory attribute");
return -1;
}
Py_XSETREF(self->row_factory, Py_NewRef(value));
return 0;
}
static PyObject *
connection_get_text_factory(PyObject *op, void *closure)
{
pysqlite_Connection *self = (pysqlite_Connection *)op;
return Py_NewRef(self->text_factory);
}
static int
connection_set_text_factory(PyObject *op, PyObject *value, void *closure)
{
pysqlite_Connection *self = (pysqlite_Connection *)op;
if (value == NULL) {
PyErr_SetString(PyExc_AttributeError,
"cannot delete text_factory attribute");
return -1;
}
Py_XSETREF(self->text_factory, Py_NewRef(value));
return 0;
}
/*[clinic input]
_sqlite3.Connection.blobopen as blobopen
@ -2620,6 +2661,10 @@ static PyGetSetDef connection_getset[] = {
{"in_transaction", pysqlite_connection_get_in_transaction, NULL},
{"autocommit", get_autocommit, set_autocommit},
{"__text_signature__", get_sig, NULL},
{"row_factory", connection_get_row_factory,
connection_set_row_factory},
{"text_factory", connection_get_text_factory,
connection_set_text_factory},
{NULL}
};
@ -2667,8 +2712,6 @@ static struct PyMemberDef connection_members[] =
{"InternalError", _Py_T_OBJECT, offsetof(pysqlite_Connection, InternalError), Py_READONLY},
{"ProgrammingError", _Py_T_OBJECT, offsetof(pysqlite_Connection, ProgrammingError), Py_READONLY},
{"NotSupportedError", _Py_T_OBJECT, offsetof(pysqlite_Connection, NotSupportedError), Py_READONLY},
{"row_factory", _Py_T_OBJECT, offsetof(pysqlite_Connection, row_factory)},
{"text_factory", _Py_T_OBJECT, offsetof(pysqlite_Connection, text_factory)},
{NULL}
};