Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-105375: Improve error handling in sqlite3 collation callback (GH-1…
…05412)

Check for error after each call to PyUnicode_FromStringAndSize().
(cherry picked from commit a24a780)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
  • Loading branch information
erlend-aasland authored and miss-islington committed Jun 7, 2023
commit 4da629754f7af02d6d0b68943ad2c2934815cdaa
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 5 additions & 3 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1792,10 +1792,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;
Expand Down