Repository navigation
gh-152817: Prevent deletion of sqlite3 cursor.row_factory attr, missed from: gh-149738
#152818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
beb6a26
6db8641
3d7bd8f
f297152
f09a339
110140b
3d4a61a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| :mod:`sqlite3`: Disallow removing ``row_factory`` and ``text_factory`` attributes | ||
| of a connection to prevent a crash on a query. | ||
| of a connection or cursor to prevent a crash on a query. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1400,13 +1400,33 @@ static struct PyMemberDef cursor_members[] = | |
| {"description", _Py_T_OBJECT, offsetof(pysqlite_Cursor, description), Py_READONLY}, | ||
| {"lastrowid", _Py_T_OBJECT, offsetof(pysqlite_Cursor, lastrowid), Py_READONLY}, | ||
| {"rowcount", Py_T_LONG, offsetof(pysqlite_Cursor, rowcount), Py_READONLY}, | ||
| {"row_factory", _Py_T_OBJECT, offsetof(pysqlite_Cursor, row_factory), 0}, | ||
| {"__weaklistoffset__", Py_T_PYSSIZET, offsetof(pysqlite_Cursor, in_weakreflist), Py_READONLY}, | ||
| {NULL} | ||
| }; | ||
|
|
||
| static PyObject * | ||
| cursor_get_row_factory(PyObject *op, void *closure) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style nitpick: use |
||
| { | ||
| pysqlite_Cursor *self = (pysqlite_Cursor *)op; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
| return Py_NewRef(self->row_factory); | ||
| } | ||
|
|
||
| static int | ||
| cursor_set_row_factory(PyObject *op, PyObject *value, void *closure) | ||
| { | ||
| pysqlite_Cursor *self = (pysqlite_Cursor *)op; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same. |
||
| if (value == NULL) { | ||
| PyErr_SetString(PyExc_AttributeError, | ||
| "cannot delete row_factory attribute"); | ||
| return -1; | ||
| } | ||
| Py_XSETREF(self->row_factory, Py_NewRef(value)); | ||
|
sobolevn marked this conversation as resolved.
Resolved
|
||
| return 0; | ||
| } | ||
|
|
||
| static struct PyGetSetDef cursor_getsets[] = { | ||
| _SQLITE3_CURSOR_ARRAYSIZE_GETSETDEF | ||
| {"row_factory", cursor_get_row_factory, cursor_set_row_factory}, | ||
| {NULL}, | ||
| }; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.