[Python-checkins] bpo-42655: Fix subprocess extra_groups gid conversion (GH-23762)
miss-islington
webhook-mailer at python.org
Tue Dec 29 08:22:18 EST 2020
https://github.com/python/cpython/commit/3966e2ea412a5f190dc8655d9aa7a15c08c4e280
commit: 3966e2ea412a5f190dc8655d9aa7a15c08c4e280
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2020-12-29T05:22:13-08:00
summary:
bpo-42655: Fix subprocess extra_groups gid conversion (GH-23762)
(cherry picked from commit 0159e5efeebd12b3cf365c8569ca000eac7cb03e)
Co-authored-by: Jakub Kulík <Kulikjak at gmail.com>
files:
A Misc/NEWS.d/next/Library/2020-12-25-12-32-47.bpo-42655.W5ytpV.rst
M Modules/_posixsubprocess.c
M Modules/posixmodule.c
M Modules/posixmodule.h
diff --git a/Misc/NEWS.d/next/Library/2020-12-25-12-32-47.bpo-42655.W5ytpV.rst b/Misc/NEWS.d/next/Library/2020-12-25-12-32-47.bpo-42655.W5ytpV.rst
new file mode 100644
index 0000000000000..57c9a666e395a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-12-25-12-32-47.bpo-42655.W5ytpV.rst
@@ -0,0 +1,2 @@
+:mod:`subprocess` *extra_groups* is now correctly passed into setgroups()
+system call.
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c
index c266fd1ec1756..d64e0a1cfa06d 100644
--- a/Modules/_posixsubprocess.c
+++ b/Modules/_posixsubprocess.c
@@ -753,7 +753,7 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
if (groups_list != Py_None) {
#ifdef HAVE_SETGROUPS
Py_ssize_t i;
- unsigned long gid;
+ gid_t gid;
if (!PyList_Check(groups_list)) {
PyErr_SetString(PyExc_TypeError,
@@ -787,10 +787,6 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
Py_DECREF(elem);
goto cleanup;
} else {
- /* In posixmodule.c UnsignedLong is used as a fallback value
- * if the value provided does not fit in a Long. Since we are
- * already doing the bounds checking on the Python side, we
- * can go directly to an UnsignedLong here. */
if (!_Py_Gid_Converter(elem, &gid)) {
Py_DECREF(elem);
PyErr_SetString(PyExc_ValueError, "invalid group id");
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 12f72f525f7ae..d2ce8339e61f0 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -632,7 +632,7 @@ _PyLong_FromGid(gid_t gid)
}
int
-_Py_Uid_Converter(PyObject *obj, void *p)
+_Py_Uid_Converter(PyObject *obj, uid_t *p)
{
uid_t uid;
PyObject *index;
@@ -719,7 +719,7 @@ _Py_Uid_Converter(PyObject *obj, void *p)
success:
Py_DECREF(index);
- *(uid_t *)p = uid;
+ *p = uid;
return 1;
underflow:
@@ -738,7 +738,7 @@ _Py_Uid_Converter(PyObject *obj, void *p)
}
int
-_Py_Gid_Converter(PyObject *obj, void *p)
+_Py_Gid_Converter(PyObject *obj, gid_t *p)
{
gid_t gid;
PyObject *index;
@@ -826,7 +826,7 @@ _Py_Gid_Converter(PyObject *obj, void *p)
success:
Py_DECREF(index);
- *(gid_t *)p = gid;
+ *p = gid;
return 1;
underflow:
diff --git a/Modules/posixmodule.h b/Modules/posixmodule.h
index 1e00562abc337..711ac686934b0 100644
--- a/Modules/posixmodule.h
+++ b/Modules/posixmodule.h
@@ -14,8 +14,8 @@ extern "C" {
#ifndef MS_WINDOWS
PyAPI_FUNC(PyObject *) _PyLong_FromUid(uid_t);
PyAPI_FUNC(PyObject *) _PyLong_FromGid(gid_t);
-PyAPI_FUNC(int) _Py_Uid_Converter(PyObject *, void *);
-PyAPI_FUNC(int) _Py_Gid_Converter(PyObject *, void *);
+PyAPI_FUNC(int) _Py_Uid_Converter(PyObject *, uid_t *);
+PyAPI_FUNC(int) _Py_Gid_Converter(PyObject *, gid_t *);
#endif /* MS_WINDOWS */
#if defined(PYPTHREAD_SIGMASK) || defined(HAVE_SIGWAIT) || \
More information about the Python-checkins
mailing list