[3.12] gh-105375: Improve error handling in sqlite3 collation callback (GH-105412) (#105440)

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

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
This commit is contained in:
Miss Islington (bot) 2023-06-07 04:43:18 -07:00 committed by GitHub
parent c84d4d165d
commit bb6ea72003
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View file

@ -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.

View 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;