Visitar URL original
bpo-31746: Fixed Segfaults in the sqlite module when uninitialized. by lielfr · Pull Request #3946 · python/cpython · GitHub
Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-31746: Fixed Segfaults in the sqlite module when uninitialized.
  • Loading branch information
lielfr committed Apr 28, 2021
commit bbe3a0ebb700ba2c1fbf348e74ca4b2dcfd84a48
9 changes: 9 additions & 0 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ pysqlite_connection_dealloc(pysqlite_Connection *self)
*/
int pysqlite_connection_register_cursor(pysqlite_Connection* connection, PyObject* cursor)
{
if (!connection || !connection->cursors) {
PyErr_Format(PyExc_RuntimeError,
Comment thread
lielfr marked this conversation as resolved.
Outdated
"Tried to get a cursor of an uninitialized connection."
);
goto error;
}
PyObject* weakref;

weakref = PyWeakref_NewRef((PyObject*)cursor, NULL);
Expand Down Expand Up @@ -1225,6 +1231,9 @@ int pysqlite_check_thread(pysqlite_Connection* self)

static PyObject* pysqlite_connection_get_isolation_level(pysqlite_Connection* self, void* unused)
{
if (!self || !self->isolation_level) {
Py_RETURN_NONE;
Comment thread
lielfr marked this conversation as resolved.
Outdated
}
Comment on lines +1254 to +1258

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If self->initialized is only set if pysqlite_connection_init was successful, this can be reduced to:

Suggested change
if (!self || !self->isolation_level) {
PyErr_Format(pysqlite_ProgrammingError,
"Object is null or isolation_level is uninitialized.");
return 0;
}
if (!pysqlite_check_connection(self)) {
return NULL;
}

return Py_NewRef(self->isolation_level);
}

Expand Down