Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
Gh-142174: Explicitly disallow _as_parameter_ returning tuples#142175
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.
Changes from all commits
62d370f3fa95266e367535c2c893667e0f0b41f966ef2bdd121660107d801d5ff176f1File 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
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. Please don't put your name in the filename. If you'd like to get credit, you can add something like "Patch by Your Name." at the end of the entry. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
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. Extra newline. | ||
| Analysis confirms that :mod:`ctypes` does not support returning tuples from ``_as_parameter_`` for default conversions. Attempting to do so raises a :exc:`TypeError` (wrapped in a ``ctypes.ArgumentError``), meaning the described security risk does not exist in the current codebase. | ||
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. This NEWS entry is too verbose and if returning tuples from | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -620,9 +620,6 @@ PyType_Spec carg_spec ={ | ||
| * by value, or a 2-tuple or 3-tuple which will be used according | ||
| * to point 2 above. The third item (if any), is ignored. It is normally | ||
| * used to keep the object alive where this parameter refers to. | ||
| * XXX This convention is dangerous - you can construct arbitrary tuples | ||
| * in Python and pass them. Would it be safer to use a custom container | ||
| * datatype instead of a tuple? | ||
| * | ||
| * 4. Other Python objects cannot be passed as parameters - an exception is raised. | ||
| * | ||
| @@ -742,6 +739,13 @@ static int ConvParam(ctypes_state *st, | ||
| attribute) | ||
| */ | ||
| if (arg){ | ||
| if (PyTuple_Check(arg) || PyList_Check(arg)){ | ||
| Py_DECREF(arg); | ||
| PyErr_Format(PyExc_TypeError, | ||
| "Don't know how to convert parameter %d", | ||
| Py_SAFE_DOWNCAST(index, Py_ssize_t, int)); | ||
| return -1; | ||
| } | ||
| int result; | ||
Comment on lines +742 to 749 Member
| ||
| result = ConvParam(st, arg, index, pa); | ||
| Py_DECREF(arg); | ||
| @@ -1512,7 +1516,7 @@ static void *libsystem_b_handle; | ||
| static bool (*_dyld_shared_cache_contains_path)(const char *path); | ||
| __attribute__((constructor)) void load_dyld_shared_cache_contains_path(void){ | ||
| libsystem_b_handle = dlopen("/usr/lib/libSystem.B.dylib", RTLD_LAZY); | ||
| libsystem_b_handle = dlopen("/usr/lib/libSystem.B.dylib", RTLD_LAZY | RTLD_GLOBAL); | ||
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. Hmm, this looks unrelated as well. | ||
| if (libsystem_b_handle != NULL){ | ||
| _dyld_shared_cache_contains_path = dlsym(libsystem_b_handle, "_dyld_shared_cache_contains_path"); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -91,7 +91,9 @@ reftotal_add(PyThreadState *tstate, Py_ssize_t n) | ||
| Py_ssize_t reftotal = tstate_impl->reftotal + n; | ||
| _Py_atomic_store_ssize_relaxed(&tstate_impl->reftotal, reftotal); | ||
| #else | ||
| REFTOTAL(tstate->interp) += n; | ||
| if (tstate && tstate->interp){ | ||
| REFTOTAL(tstate->interp) += n; | ||
| } | ||
Comment on lines +94 to +96 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. This looks unrelated to this change and is incorrect. | ||
| #endif | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
This test already passes on main.