From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 7 Jun 2023 21:22:01 +0000 (-0700) Subject: [3.11] gh-105375: Improve error handling in sqlite3 collation callback (GH-105412... X-Git-Tag: v3.11.5~316 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=571ec56b6503bbd1687c7f62203dab4c2dfe20ba;p=thirdparty%2FPython%2Fcpython.git [3.11] gh-105375: Improve error handling in sqlite3 collation callback (GH-105412) (#105441) Check for error after each call to PyUnicode_FromStringAndSize(). (cherry picked from commit a24a780d937109a0982d807473ae410cc75b0e3b) Co-authored-by: Erlend E. Aasland --- diff --git a/Misc/NEWS.d/next/Library/2023-06-07-00-09-52.gh-issue-105375.Y_9D4n.rst b/Misc/NEWS.d/next/Library/2023-06-07-00-09-52.gh-issue-105375.Y_9D4n.rst new file mode 100644 index 000000000000..ec10d63822c2 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-06-07-00-09-52.gh-issue-105375.Y_9D4n.rst @@ -0,0 +1,2 @@ +Fix a bug in :mod:`sqlite3` where an exception could be overwritten in the +:meth:`collation ` callback. diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 9c7eb85df3b7..e3650de7fb16 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -1792,10 +1792,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;