New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect error handling for APIs that can raise exceptions #105375
Comments
This comment was marked as outdated.
This comment was marked as outdated.
Check for error after each call to PyUnicode_FromStringAndSize().
…pythonGH-105412) Check for error after each call to PyUnicode_FromStringAndSize(). (cherry picked from commit a24a780) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
…pythonGH-105412) Check for error after each call to PyUnicode_FromStringAndSize(). (cherry picked from commit a24a780) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Error handling was deferred in some cases, which could potentially lead to exceptions being overwritten.
There were many "init" functions of C extensions calling all C functions without checking for exceptions, and only checking for exceptions once at the end. Most of them have been fixed with better error checking, but not all of them yet. |
See issue #105374 about C API being error prone: when it's unclear if passing NULL was done on purpose or by mistake |
See also capi-workgroup/problems#47 |
(cherry picked from commit 20a56d8) Add proper error handling to add_errors_module() to prevent exceptions from possibly being overwritten. Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
(cherry picked from commit 20a56d8) Add proper error handling to add_errors_module() to prevent exceptions from possibly being overwritten. Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Thank you, @erlend-aasland. These are minor errors, but it is nice to have the code cleaner. Although you introduced new bugs in #105475 and #105611 related to clearing non-initialized references. |
Thanks for double-checking, Serhiy. I really appreciate that. I will address your remarks. |
Refs #105673 |
…fields PyObject_GC_New() only initialises the object header. All other fields must be explicitly initialised to prevent manipulation of uninitialised fields in dealloc. Align initialisation order with the layout of the object structs.
…#105686) All fields must be explicitly initialised to prevent manipulation of uninitialised fields in dealloc. Align initialisation order with the layout of the object structs.
…fields (pythonGH-105686) All fields must be explicitly initialised to prevent manipulation of uninitialised fields in dealloc. Align initialisation order with the layout of the object structs. (cherry picked from commit ca3cc4b) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
…Object fields (python#105686) All fields must be explicitly initialised to prevent manipulation of uninitialised fields in dealloc. Align initialisation order with the layout of the object structs. (cherry picked from commit ca3cc4b) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
… fields (GH-105686) (#105710) All fields must be explicitly initialised to prevent manipulation of uninitialised fields in dealloc. Align initialisation order with the layout of the object structs. (cherry picked from commit ca3cc4b) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* main: pythongh-105540: Fix code generator tests (python#105707) pythongh-105375: Explicitly initialise all {Pickler,Unpickler}Object fields (python#105686) pythongh-105331: Change `asyncio.sleep` to raise ``ValueError` for nan (python#105641) Remove support for legacy bytecode instructions (python#105705)
… fields (#105686) (#105711) * [3.11] gh-105375: Explicitly initialise all {Pickler,Unpickler}Object fields (#105686) All fields must be explicitly initialised to prevent manipulation of uninitialised fields in dealloc. Align initialisation order with the layout of the object structs. (cherry picked from commit ca3cc4b) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
…5667) Prevent exceptions from possibly being overwritten in case of multiple failures.
…Stream() (python#105667) Prevent exceptions from possibly being overwritten in case of multiple failures. (cherry picked from commit 217589d) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
…Stream() (python#105667) Prevent exceptions from possibly being overwritten in case of multiple failures. (cherry picked from commit 217589d) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
For example, in the collation callback two
str
objects (string1
andstring2
) are created usingPyUnicode_FromStringAndSize
. Error handling should happen directly after each call toPyUnicode_FromStringAndSize
:cpython/Modules/_sqlite/connection.c
Lines 1870 to 1875 in 0cb6b9b
Other cases where error handling is not done immediately after the API has been used:
zoneinfo
module #105586_testcapi/heaptype.c
#105608I might have missed some; I did not do a complete audit yet.
Linked PRs
zoneinfo
module #105586_testcapi/heaptype.c
#105608zoneinfo
module (GH-105586) #105612zoneinfo
module (GH-105586) #105613_testcapi/heaptype.c
(GH-105608) #105615The text was updated successfully, but these errors were encountered: