Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
bpo-43916: Add _PyType_DisabledNew to prevent new heap types from being created uninitialised#25653
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
Uh oh!
There was an error while loading. Please reload this page.
bpo-43916: Add _PyType_DisabledNew to prevent new heap types from being created uninitialised #25653
Changes from all commits
36150d6dbebde554646a502829da0c3872e45169ff69b19bc2cc4dd1d41b7993f34237eee30445c7f04770dcae37fb93a966552f0ce16da51450485File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -29,6 +29,9 @@ _PyType_HasFeature(PyTypeObject *type, unsigned long feature){ | ||
| extern void _PyType_InitCache(PyInterpreterState *interp); | ||
| PyAPI_FUNC(PyObject *) _PyType_DisabledNew(PyTypeObject *type, PyObject *args, | ||
| PyObject *kwds); | ||
erlend-aasland marked this conversation as resolved. Outdated Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| /* Inline functions trading binary compatibility for speed: | ||
| _PyObject_Init() is the fast version of PyObject_Init(), and | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -58,6 +58,13 @@ def tearDown(self): | ||
| os_helper.unlink(teardown_file) | ||
| self._warnings_manager.__exit__(None, None, None) | ||
| @support.cpython_only | ||
| def test_uninitialised_new(self): | ||
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. It is already tested in | ||
| # Prevent heap types from being created uninitialised (bpo-43916) | ||
| self.assertRaises(TypeError, posix.DirEntry) | ||
| tp = type(posix.scandir()) | ||
| self.assertRaises(TypeError, tp) | ||
| def testNoArgFunctions(self): | ||
| # test posix functions which take no arguments and have | ||
| # no side-effects which we need to cleanup (e.g., fork, wait, abort) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Fix regressions for extension modules that have been converted to :ref:`heap | ||
| types <heap-types>`. Inheritance differs for *static types* and *heap | ||
| types*: A *static type* with its :c:member:`~PyTypeObject.tp_new` set to | ||
| ``NULL`` does not have a public contructor, but *heap types* inherit | ||
| contructors from their base classes, resulting in it being possible to | ||
| create instances without proper initialisation, possibly resulting in a | ||
| crash. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -44,6 +44,9 @@ | ||
| #include <crtdbg.h> | ||
| #include "winreparse.h" | ||
| // Include pycore_object.h to avoid conflict with windows.h | ||
| #include "pycore_object.h" // _PyType_DisabledNew() | ||
| #if defined(MS_WIN32) && !defined(MS_WIN64) | ||
| #define HANDLE_TO_PYNUM(handle) \ | ||
| PyLong_FromUnsignedLong((unsigned long) handle) | ||
| @@ -325,6 +328,7 @@ static PyType_Slot winapi_overlapped_type_slots[] ={ | ||
| {Py_tp_doc, "OVERLAPPED structure wrapper"}, | ||
| {Py_tp_methods, overlapped_methods}, | ||
| {Py_tp_members, overlapped_members}, | ||
| {Py_tp_new, _PyType_DisabledNew}, | ||
erlend-aasland marked this conversation as resolved. Outdated Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| {0,0} | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.