-
-
Notifications
You must be signed in to change notification settings - Fork 36.8k
gh-151842: Make _PyXI_FreeExcInfo NULL-safe to fix crash on capture_exception() OOM (OOM-0031) #151843
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
gh-151842: Make _PyXI_FreeExcInfo NULL-safe to fix crash on capture_exception() OOM (OOM-0031) #151843
Changes from 3 commits
57a99d4
7d517f5
48c87aa
e4f031f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Fix a segfault in ``_interpreters.capture_exception()`` under memory | ||
| pressure. When ``_PyXI_NewExcInfo()`` failed to allocate, the cleanup path | ||
| called ``_PyXI_FreeExcInfo(NULL)``, which then dereferenced offset 0 in | ||
| ``_excinfo_clear_type()``. ``_PyXI_FreeExcInfo()`` now accepts ``NULL`` like | ||
| the surrounding ``PyMem_RawFree`` idiom. Patch by Amrutha Modela. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is too technical. Users reading the changelog will have no idea what this means. Let's just say something like "Fix crash when |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1709,6 +1709,11 @@ _PyXI_NewExcInfo(PyObject *exc) | |
| void | ||
| _PyXI_FreeExcInfo(_PyXI_excinfo *info) | ||
| { | ||
| if (info == NULL) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to not allow Please, take a look at #152013 You can copy my solution from there. I missed that you had a PR already and created my own one. But, I closed it, so you can contribute :) This is not the only problem in the same function.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // Matches the PyMem_RawFree(NULL) idiom: callers may pass NULL when | ||
| // _PyXI_NewExcInfo() failed (e.g. under OOM) before any allocation. | ||
| return; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, but I don't think this is the right approach. Functions that do nothing under To me,
Please just add a |
||
| _PyXI_excinfo_clear(info); | ||
| PyMem_RawFree(info); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need a news entry here either (I think we've decided that before too, I think it was on Jelle's PR), additionally it describes a lot of internal things (please see the devguide for more information about what we want in these entries).