]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-105375: Improve error handling in sqlite3 collation callback (GH-105412...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 7 Jun 2023 11:43:18 +0000 (04:43 -0700)
committerGitHub <noreply@github.com>
Wed, 7 Jun 2023 11:43:18 +0000 (11:43 +0000)
Check for error after each call to PyUnicode_FromStringAndSize().
(cherry picked from commit a24a780d937109a0982d807473ae410cc75b0e3b)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Misc/NEWS.d/next/Library/2023-06-07-00-09-52.gh-issue-105375.Y_9D4n.rst [new file with mode: 0644]
Modules/_sqlite/connection.c

diff --git a/Misc/NEWS.d/next/Library/2023-06-07-00-09-52.gh-issue-105375.Y_9D4n.rst b/Misc/NEWS.d/next/Library/2023-06-07-00-09-52.gh-issue-105375.Y_9D4n.rst
new file mode 100644 (file)
index 0000000..ec10d63
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a bug in :mod:`sqlite3` where an exception could be overwritten in the
+:meth:`collation <sqlite3.Connection.create_collation>` callback.
index 5c57a4101c4a695ade5136a59eef76af25000782..82d23c2c30b798dfd4772ec0dc16b2d4c585e5c5 100644 (file)
@@ -1868,10 +1868,12 @@ collation_callback(void *context, int text1_length, const void *text1_data,
     }
 
     string1 = PyUnicode_FromStringAndSize((const char*)text1_data, text1_length);
+    if (string1 == NULL) {
+        goto finally;
+    }
     string2 = PyUnicode_FromStringAndSize((const char*)text2_data, text2_length);
-
-    if (!string1 || !string2) {
-        goto finally; /* failed to allocate strings */
+    if (string2 == NULL) {
+        goto finally;
     }
 
     callback_context *ctx = (callback_context *)context;