mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-117021: Fix integer overflow in PyLong_AsPid() on non-Windows 64-bit platforms (GH-117064)
This commit is contained in:
parent
8182319de3
commit
519b2ae22b
7 changed files with 74 additions and 2 deletions
|
|
@ -92,12 +92,24 @@ pylong_fromnativebytes(PyObject *module, PyObject *args)
|
|||
return res;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
pylong_aspid(PyObject *module, PyObject *arg)
|
||||
{
|
||||
NULLABLE(arg);
|
||||
pid_t value = PyLong_AsPid(arg);
|
||||
if (value == -1 && PyErr_Occurred()) {
|
||||
return NULL;
|
||||
}
|
||||
return PyLong_FromPid(value);
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef test_methods[] = {
|
||||
_TESTCAPI_CALL_LONG_COMPACT_API_METHODDEF
|
||||
{"pylong_fromunicodeobject", pylong_fromunicodeobject, METH_VARARGS},
|
||||
{"pylong_asnativebytes", pylong_asnativebytes, METH_VARARGS},
|
||||
{"pylong_fromnativebytes", pylong_fromnativebytes, METH_VARARGS},
|
||||
{"pylong_aspid", pylong_aspid, METH_O},
|
||||
{NULL},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -3975,6 +3975,7 @@ PyInit__testcapi(void)
|
|||
PyModule_AddObject(m, "SIZEOF_WCHAR_T", PyLong_FromSsize_t(sizeof(wchar_t)));
|
||||
PyModule_AddObject(m, "SIZEOF_VOID_P", PyLong_FromSsize_t(sizeof(void*)));
|
||||
PyModule_AddObject(m, "SIZEOF_TIME_T", PyLong_FromSsize_t(sizeof(time_t)));
|
||||
PyModule_AddObject(m, "SIZEOF_PID_T", PyLong_FromSsize_t(sizeof(pid_t)));
|
||||
PyModule_AddObject(m, "Py_Version", PyLong_FromUnsignedLong(Py_Version));
|
||||
Py_INCREF(&PyInstanceMethod_Type);
|
||||
PyModule_AddObject(m, "instancemethod", (PyObject *)&PyInstanceMethod_Type);
|
||||
|
|
|
|||
|
|
@ -746,6 +746,17 @@ pylong_asvoidptr(PyObject *module, PyObject *arg)
|
|||
return Py_NewRef((PyObject *)value);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
pylong_aspid(PyObject *module, PyObject *arg)
|
||||
{
|
||||
NULLABLE(arg);
|
||||
pid_t value = PyLong_AsPid(arg);
|
||||
if (value == -1 && PyErr_Occurred()) {
|
||||
return NULL;
|
||||
}
|
||||
return PyLong_FromPid(value);
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef test_methods[] = {
|
||||
_TESTLIMITEDCAPI_TEST_LONG_AND_OVERFLOW_METHODDEF
|
||||
|
|
@ -773,6 +784,7 @@ static PyMethodDef test_methods[] = {
|
|||
{"pylong_as_size_t", pylong_as_size_t, METH_O},
|
||||
{"pylong_asdouble", pylong_asdouble, METH_O},
|
||||
{"pylong_asvoidptr", pylong_asvoidptr, METH_O},
|
||||
{"pylong_aspid", pylong_aspid, METH_O},
|
||||
{NULL},
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue