Skip to content

Commit 571ec56

Browse files
[3.11] gh-105375: Improve error handling in sqlite3 collation callback (GH-105412) (#105441)
Check for error after each call to PyUnicode_FromStringAndSize(). (cherry picked from commit a24a780) Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent 18e9fd8 commit 571ec56

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a bug in :mod:`sqlite3` where an exception could be overwritten in the
2+
:meth:`collation <sqlite3.Connection.create_collation>` callback.

Modules/_sqlite/connection.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -1792,10 +1792,12 @@ collation_callback(void *context, int text1_length, const void *text1_data,
17921792
}
17931793

17941794
string1 = PyUnicode_FromStringAndSize((const char*)text1_data, text1_length);
1795+
if (string1 == NULL) {
1796+
goto finally;
1797+
}
17951798
string2 = PyUnicode_FromStringAndSize((const char*)text2_data, text2_length);
1796-
1797-
if (!string1 || !string2) {
1798-
goto finally; /* failed to allocate strings */
1799+
if (string2 == NULL) {
1800+
goto finally;
17991801
}
18001802

18011803
callback_context *ctx = (callback_context *)context;

0 commit comments

Comments
 (0)