[Python-checkins] bpo-43083: Fix error handling in _sqlite3 (GH-24395)

serhiy-storchaka webhook-mailer at python.org
Sun Jan 31 10:42:50 EST 2021


https://github.com/python/cpython/commit/9073180db521dc83e6216ff0da1479d00167f643
commit: 9073180db521dc83e6216ff0da1479d00167f643
branch: master
author: Serhiy Storchaka <storchaka at gmail.com>
committer: serhiy-storchaka <storchaka at gmail.com>
date: 2021-01-31T17:42:38+02:00
summary:

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

files:
M Modules/_sqlite/connection.c
M Modules/_sqlite/cursor.c

diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index dbe5dd1ec13fa..370dc1a30e46a 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -1772,7 +1772,11 @@ pysqlite_connection_create_collation_impl(pysqlite_Connection *self,
                                   (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 0852aa940264a..f8fe11ed1ea75 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -567,11 +567,13 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation
         }
 
         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) {
@@ -842,8 +844,11 @@ pysqlite_cursor_fetchmany_impl(pysqlite_Cursor *self, int maxrows)
     }
 
     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;
@@ -877,8 +882,11 @@ pysqlite_cursor_fetchall_impl(pysqlite_Cursor *self)
     }
 
     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()) {



More information about the Python-checkins mailing list