-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
gh-143198: fix SIGSEGV in sqlite3.executemany with concurrent mutations
#143210
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
base: main
Are you sure you want to change the base?
Changes from all commits
037b421
cc0f483
3952cfe
b0c8b16
ae2a5de
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 |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| :mod:`sqlite3`: fix crashes in :meth:`Connection.executemany <sqlite3.Connection.executemany>` | ||
| and :meth:`Cursor.executemany <sqlite3.Cursor.executemany>` when iterating over | ||
| the query's parameters closes the current connection. Patch by Bénédikt Tran. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -870,6 +870,12 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| // PyObject_GetIter() may have a side-effect on the connection's state. | ||||||
| // See: https://github.com/python/cpython/issues/143198. | ||||||
| if (!pysqlite_check_connection(self->connection)) { | ||||||
| goto error; | ||||||
| } | ||||||
|
|
||||||
| /* reset description */ | ||||||
| Py_INCREF(Py_None); | ||||||
| Py_SETREF(self->description, Py_None); | ||||||
|
|
@@ -925,6 +931,11 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation | |||||
| if (!parameters) { | ||||||
| break; | ||||||
| } | ||||||
| // PyIter_Next() may have a side-effect on the connection's state. | ||||||
| // See: https://github.com/python/cpython/issues/143198. | ||||||
| if (!pysqlite_check_connection(self->connection)) { | ||||||
|
Member
Author
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.
Suggested change
Strictly speaking, this check is redundant when dealing with |
||||||
| goto error; | ||||||
| } | ||||||
|
|
||||||
| bind_parameters(state, self->statement, parameters); | ||||||
| if (PyErr_Occurred()) { | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: if
parametersis NULL and we have an active exception, we break the loop. It should only happen when we are having a custom iterator, that is,multiple = 1. As such, we wouldn't branch into theif (!multiple)and we wouldn't callPyLong_FromLongLong.However, I'll add tomorrow some assertions because it's not entirely clear from the code alone.