mirror of https://github.com/python/cpython
gh-105375: Improve error handling in sqlite3 collation callback (#105412)
Check for error after each call to PyUnicode_FromStringAndSize().
This commit is contained in:
parent
ffd2654550
commit
a24a780d93
|
@ -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.
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue