Skip to content

Commit

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

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
miss-islington and erlend-aasland committed Jun 7, 2023
1 parent c84d4d1 commit bb6ea72
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
@@ -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
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 bb6ea72

Please sign in to comment.