bpo-37012: Fix a possible crash due to PyType_FromSpecWithBases()#10304
Conversation
If the PyObject_MALLOC() call failed in PyType_FromSpecWithBases(), PyObject_Free() would be called on a static string in type_dealloc().
|
@ZackerySpytz the "skip issue" label (and any other label for that matter) can only be added by developers. I was also confused when I started doing PRs, and tried adding "skip issue" in several places myself :) I mention this just to let you know why it didn't work. |
|
I think this might require issue and news entry. |
| size_t len = strlen(old_doc)+1; | ||
| char *tp_doc = PyObject_MALLOC(len); | ||
| if (tp_doc == NULL) { | ||
| type->tp_doc = NULL; |
There was a problem hiding this comment.
In what circumstances it is not NULL? PyType_GenericAlloc() fills the type object with zeros.
|
I removed the " needs backport to 3.6" label, the 3.6 branch no longer accept bugfixes (only security fixes are accepted): https://devguide.python.org/#status-of-python-branches |
|
I believe Serhyi's question is valid. If you have an answer, please re-open the PR. (Is this silencing some static analyzer? ) |
|
@encukou Please reopen this PR.
|
|
My apologies, you're right. |
|
Thanks @ZackerySpytz for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.7. |
If the PyObject_MALLOC() call failed in PyType_FromSpecWithBases(), PyObject_Free() would be called on a static string in type_dealloc(). (cherry picked from commit 0613c1e) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
|
GH-13223 is a backport of this pull request to the 3.7 branch. |
|
Sorry, @ZackerySpytz and @encukou, I could not cleanly backport this to |
|
Instead of reverting the change that we just made, what about not writing into tp_doc if it's value makes the type inconsistent? What about this patch: |
If the PyObject_MALLOC() call failed in PyType_FromSpecWithBases(), PyObject_Free() would be called on a static string in type_dealloc(). (cherry picked from commit 0613c1e) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
…signments The main slot assignment loop is now if-else if ladder, making the control flow clearer. Based on suggestion by Victor Stinner in: python#10304
…signments (pythonGH-13496) The main slot assignment loop is now if-else if ladder, making the control flow clearer. Based on suggestion by Victor Stinner in: python#10304
If the PyObject_MALLOC() call failed in PyType_FromSpecWithBases(),
PyObject_Free() would be called on a static string in type_dealloc().
https://bugs.python.org/issue37012