]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43083: Fix error handling in _sqlite3 (GH-24395)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 31 Jan 2021 16:06:15 +0000 (08:06 -0800)
committerGitHub <noreply@github.com>
Sun, 31 Jan 2021 16:06:15 +0000 (08:06 -0800)
(cherry picked from commit 9073180db521dc83e6216ff0da1479d00167f643)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Modules/_sqlite/connection.c
Modules/_sqlite/cursor.c

index b80037347f13b5023d6f894e8fd2782062208d10..d20339ca3f7dfdce5aca06dd1d34cb570a1474cb 100644 (file)
@@ -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;
     }
index 5cfb4b97d61dfe3fb2aa8e35838b91b037c1a1d8..dd0ce7e1ea6a3368d3e892bcc1c437f4f6f741ca 100644 (file)
@@ -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()) {