gh-105375: Improve error handling in sqlite3 collation callback (#105412)

Check for error after each call to PyUnicode_FromStringAndSize().
This commit is contained in:
Erlend E. Aasland 2023-06-07 13:10:28 +02:00 committed by GitHub
parent ffd2654550
commit a24a780d93
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); string1 = PyUnicode_FromStringAndSize((const char*)text1_data, text1_length);
if (string1 == NULL) {
goto finally;
}
string2 = PyUnicode_FromStringAndSize((const char*)text2_data, text2_length); string2 = PyUnicode_FromStringAndSize((const char*)text2_data, text2_length);
if (string2 == NULL) {
if (!string1 || !string2) { goto finally;
goto finally; /* failed to allocate strings */
} }
callback_context *ctx = (callback_context *)context; callback_context *ctx = (callback_context *)context;