| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
This is test code, so it doesn't really matter, but it's always better to be safe than sorry. Thanks. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Description
During a security and robustness audit of C-API usage using our static analysis tool, we identified a potential Null Pointer Dereference (NPD) in src/greenlet/tests/_test_extension.c.
In the test_throw function, Py_BuildValue("s", msg) is called to create a string object. According to the Python C-API contract, if memory allocation fails (OOM), it returns NULL and sets a MemoryError. However, the return value msg_obj is currently not checked before being used.
If msg_obj is NULL, it leads to a double crash hazard:
This hard crash truncates the exception lifecycle, destroying the original MemoryError state and preventing graceful failure.
Proposed Fix
We added a standard NULL check immediately after Py_BuildValue. If allocation fails, the function now safely returns NULL to propagate the exception properly.
Impact
This PR improves the robustness of the test extension, ensuring that extreme memory exhaustion scenarios are handled gracefully without taking down the entire interpreter process.