summaryrefslogtreecommitdiffstats
path: root/Modules/_testcapi
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-03-20 14:44:05 (GMT)
committerGitHub <noreply@github.com>2024-03-20 14:44:05 (GMT)
commitda2f9d1417a7d28df6e1ced87d64ecf28acb0a5f (patch)
tree9b1c411e9c5ba14971109cc512c10dcdde2bcd5a /Modules/_testcapi
parent0325a8a8cdba6c091bcbbb3c995f3bf1d1217012 (diff)
downloadcpython-da2f9d1417a7d28df6e1ced87d64ecf28acb0a5f.zip
cpython-da2f9d1417a7d28df6e1ced87d64ecf28acb0a5f.tar.gz
cpython-da2f9d1417a7d28df6e1ced87d64ecf28acb0a5f.tar.bz2
[3.12] gh-117021: Fix integer overflow in PyLong_AsPid() on non-Windows 64-bit platforms (GH-117064) (GH-117070)
(cherry picked from commit 519b2ae22b54760475bbf62b9558d453c703f9c6)
Diffstat (limited to 'Modules/_testcapi')
-rw-r--r--Modules/_testcapi/long.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/Modules/_testcapi/long.c b/Modules/_testcapi/long.c
index 213c676..9c5a0e3 100644
--- a/Modules/_testcapi/long.c
+++ b/Modules/_testcapi/long.c
@@ -750,6 +750,18 @@ 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[] = {
{"test_long_and_overflow", test_long_and_overflow, METH_NOARGS},
{"test_long_api", test_long_api, METH_NOARGS},
@@ -778,6 +790,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},
};