Skip to content

Commit a24a780

Browse files
gh-105375: Improve error handling in sqlite3 collation callback (#105412)
Check for error after each call to PyUnicode_FromStringAndSize().
1 parent ffd2654 commit a24a780

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a bug in :mod:`sqlite3` where an exception could be overwritten in the
2+
:meth:`collation <sqlite3.Connection.create_collation>` callback.

Modules/_sqlite/connection.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,10 +1868,12 @@ collation_callback(void *context, int text1_length, const void *text1_data,
18681868
}
18691869

18701870
string1 = PyUnicode_FromStringAndSize((const char*)text1_data, text1_length);
1871+
if (string1 == NULL) {
1872+
goto finally;
1873+
}
18711874
string2 = PyUnicode_FromStringAndSize((const char*)text2_data, text2_length);
1872-
1873-
if (!string1 || !string2) {
1874-
goto finally; /* failed to allocate strings */
1875+
if (string2 == NULL) {
1876+
goto finally;
18751877
}
18761878

18771879
callback_context *ctx = (callback_context *)context;

0 commit comments

Comments
 (0)