diff options
author | Erlend E. Aasland <erlend.aasland@protonmail.com> | 2023-06-07 11:10:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-07 11:10:28 (GMT) |
commit | a24a780d937109a0982d807473ae410cc75b0e3b (patch) | |
tree | ebcd37b3a88d2f2c7b637eb1f2dbf0279f87c7a5 | |
parent | ffd26545509b706437ca38bd6db6108c1d0e2326 (diff) | |
download | cpython-a24a780d937109a0982d807473ae410cc75b0e3b.zip cpython-a24a780d937109a0982d807473ae410cc75b0e3b.tar.gz cpython-a24a780d937109a0982d807473ae410cc75b0e3b.tar.bz2 |
gh-105375: Improve error handling in sqlite3 collation callback (#105412)
Check for error after each call to PyUnicode_FromStringAndSize().
-rw-r--r-- | Misc/NEWS.d/next/Library/2023-06-07-00-09-52.gh-issue-105375.Y_9D4n.rst | 2 | ||||
-rw-r--r-- | Modules/_sqlite/connection.c | 8 |
2 files changed, 7 insertions, 3 deletions
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 0000000..ec10d63 --- /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 <sqlite3.Connection.create_collation>` callback. diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 5c57a41..82d23c2 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -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; |