bpo-43083: Fix error handling in _sqlite3 (GH-24395)

https://github.com/python/cpython/commit/8a833a6f94d8c2baa6aa38abd9fc699881a... commit: 8a833a6f94d8c2baa6aa38abd9fc699881a5b0e1 branch: 3.9 author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> committer: miss-islington <31488909+miss-islington@users.noreply.github.com> date: 2021-01-31T08:06:15-08:00 summary: bpo-43083: Fix error handling in _sqlite3 (GH-24395) (cherry picked from commit 9073180db521dc83e6216ff0da1479d00167f643) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> files: M Modules/_sqlite/connection.c M Modules/_sqlite/cursor.c diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index b80037347f13b..d20339ca3f7df 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -1704,7 +1704,11 @@ pysqlite_connection_create_collation(pysqlite_Connection* self, PyObject* args) (callable != Py_None) ? callable : NULL, (callable != Py_None) ? pysqlite_collation_callback : NULL); if (rc != SQLITE_OK) { - PyDict_DelItem(self->collations, uppercase_name); + if (callable != Py_None) { + if (PyDict_DelItem(self->collations, uppercase_name) < 0) { + PyErr_Clear(); + } + } _pysqlite_seterror(self->db, NULL); goto finally; } diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 5cfb4b97d61df..dd0ce7e1ea6a3 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -569,11 +569,13 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* args) } if (!multiple) { - Py_DECREF(self->lastrowid); Py_BEGIN_ALLOW_THREADS lastrowid = sqlite3_last_insert_rowid(self->connection->db); Py_END_ALLOW_THREADS - self->lastrowid = PyLong_FromLongLong(lastrowid); + Py_SETREF(self->lastrowid, PyLong_FromLongLong(lastrowid)); + if (self->lastrowid == NULL) { + goto error; + } } if (rc == SQLITE_ROW) { @@ -802,8 +804,11 @@ PyObject* pysqlite_cursor_fetchmany(pysqlite_Cursor* self, PyObject* args, PyObj } while ((row = pysqlite_cursor_iternext(self))) { - PyList_Append(list, row); - Py_XDECREF(row); + if (PyList_Append(list, row) < 0) { + Py_DECREF(row); + break; + } + Py_DECREF(row); if (++counter == maxrows) { break; @@ -829,8 +834,11 @@ PyObject* pysqlite_cursor_fetchall(pysqlite_Cursor* self, PyObject* args) } while ((row = pysqlite_cursor_iternext(self))) { - PyList_Append(list, row); - Py_XDECREF(row); + if (PyList_Append(list, row) < 0) { + Py_DECREF(row); + break; + } + Py_DECREF(row); } if (PyErr_Occurred()) {
participants (1)
-
miss-islington