gh-94512: Fix forced arg format in AC-processed multiprocessing (GH-94517)

This commit is contained in:
Oleg Iarygin 2022-07-04 16:11:11 +03:00 committed by GitHub
parent 9b50f76fcd
commit 670f7f10cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 7 deletions

View File

@ -21,7 +21,8 @@ _multiprocessing_closesocket(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
HANDLE handle;
if (!PyArg_Parse(arg, ""F_HANDLE":closesocket", &handle)) {
handle = PyLong_AsVoidPtr(arg);
if (!handle && PyErr_Occurred()) {
goto exit;
}
return_value = _multiprocessing_closesocket_impl(module, handle);
@ -52,8 +53,15 @@ _multiprocessing_recv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
HANDLE handle;
int size;
if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"i:recv",
&handle, &size)) {
if (!_PyArg_CheckPositional("recv", nargs, 2, 2)) {
goto exit;
}
handle = PyLong_AsVoidPtr(args[0]);
if (!handle && PyErr_Occurred()) {
goto exit;
}
size = _PyLong_AsInt(args[1]);
if (size == -1 && PyErr_Occurred()) {
goto exit;
}
return_value = _multiprocessing_recv_impl(module, handle, size);
@ -84,8 +92,18 @@ _multiprocessing_send(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
HANDLE handle;
Py_buffer buf = {NULL, NULL};
if (!_PyArg_ParseStack(args, nargs, ""F_HANDLE"y*:send",
&handle, &buf)) {
if (!_PyArg_CheckPositional("send", nargs, 2, 2)) {
goto exit;
}
handle = PyLong_AsVoidPtr(args[0]);
if (!handle && PyErr_Occurred()) {
goto exit;
}
if (PyObject_GetBuffer(args[1], &buf, PyBUF_SIMPLE) != 0) {
goto exit;
}
if (!PyBuffer_IsContiguous(&buf, 'C')) {
_PyArg_BadArgument("send", "argument 2", "contiguous buffer", args[1]);
goto exit;
}
return_value = _multiprocessing_send_impl(module, handle, &buf);
@ -148,4 +166,4 @@ exit:
#ifndef _MULTIPROCESSING_SEND_METHODDEF
#define _MULTIPROCESSING_SEND_METHODDEF
#endif /* !defined(_MULTIPROCESSING_SEND_METHODDEF) */
/*[clinic end generated code: output=d3bbf69de578db7b input=a9049054013a1b77]*/
/*[clinic end generated code: output=ab64ce752f933c55 input=a9049054013a1b77]*/

View File

@ -14,8 +14,16 @@ class HANDLE_converter(CConverter):
type = "HANDLE"
format_unit = '"F_HANDLE"'
def parse_arg(self, argname, displayname):
return """
{paramname} = PyLong_AsVoidPtr({argname});
if (!{paramname} && PyErr_Occurred()) {{{{
goto exit;
}}}}
""".format(argname=argname, paramname=self.parser_name)
[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=9fad6080b79ace91]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=3e537d244034affb]*/
/*[clinic input]
module _multiprocessing