Skip to content

Commit

Permalink
gh-105375: Improve error handling in sqlite3 collation callback (#105412
Browse files Browse the repository at this point in the history
)

Check for error after each call to PyUnicode_FromStringAndSize().
  • Loading branch information
erlend-aasland authored Jun 7, 2023
1 parent ffd2654 commit a24a780
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
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 @@ -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;
Expand Down

0 comments on commit a24a780

Please sign in to comment.