Skip to content

Commit be078a1

Browse files
committed
Fix incorrect PyObject_CallFunction usage (remove extra NULL argument)
This PR fixes incorrect calls to PyObject_CallFunction where an extra NULL argument was passed despite the format string already specifying the complete argument list. PyObject_CallFunction does not use a NULL terminator; it relies solely on the format string to determine how many arguments to read. Providing more arguments than required results in undefined behavior due to va_list misalignment. The affected calls: - PyImport_Import() — "OOOOi" was given 6 arguments instead of 5 - deque_copy() — "Oi" was given 3 arguments instead of 2 Both have been corrected by removing the superfluous NULL. No functional changes beyond fixing the API misuse. Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com>
1 parent b1c9582 commit be078a1

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Modules/_collectionsmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ deque_copy_impl(dequeobject *deque)
634634
(PyObject *)deque);
635635
else
636636
result = PyObject_CallFunction((PyObject *)(Py_TYPE(deque)), "Oi",
637-
deque, old_deque->maxlen, NULL);
637+
deque, old_deque->maxlen);
638638
if (result != NULL && !PyObject_TypeCheck(result, state->deque_type)) {
639639
PyErr_Format(PyExc_TypeError,
640640
"%.200s() must return a deque, not %.200s",

Python/import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4067,7 +4067,7 @@ PyImport_Import(PyObject *module_name)
40674067
Always use absolute import here.
40684068
Calling for side-effect of import. */
40694069
r = PyObject_CallFunction(import, "OOOOi", module_name, globals,
4070-
globals, from_list, 0, NULL);
4070+
globals, from_list, 0);
40714071
if (r == NULL)
40724072
goto err;
40734073
Py_DECREF(r);

0 commit comments

Comments
 (0)