bpo-42655: Fix subprocess extra_groups gid conversion (GH-23762)

This commit is contained in:
Jakub Kulík 2020-12-29 13:58:27 +01:00 committed by GitHub
parent dd39123970
commit 0159e5efee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 11 deletions

View File

@ -0,0 +1,2 @@
:mod:`subprocess` *extra_groups* is now correctly passed into setgroups()
system call.

View File

@ -900,7 +900,7 @@ subprocess_fork_exec(PyObject *module, PyObject *args)
if (groups_list != Py_None) { if (groups_list != Py_None) {
#ifdef HAVE_SETGROUPS #ifdef HAVE_SETGROUPS
Py_ssize_t i; Py_ssize_t i;
unsigned long gid; gid_t gid;
if (!PyList_Check(groups_list)) { if (!PyList_Check(groups_list)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
@ -934,10 +934,6 @@ subprocess_fork_exec(PyObject *module, PyObject *args)
Py_DECREF(elem); Py_DECREF(elem);
goto cleanup; goto cleanup;
} else { } 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)) { if (!_Py_Gid_Converter(elem, &gid)) {
Py_DECREF(elem); Py_DECREF(elem);
PyErr_SetString(PyExc_ValueError, "invalid group id"); PyErr_SetString(PyExc_ValueError, "invalid group id");

View File

@ -672,7 +672,7 @@ _PyLong_FromGid(gid_t gid)
} }
int int
_Py_Uid_Converter(PyObject *obj, void *p) _Py_Uid_Converter(PyObject *obj, uid_t *p)
{ {
uid_t uid; uid_t uid;
PyObject *index; PyObject *index;
@ -759,7 +759,7 @@ _Py_Uid_Converter(PyObject *obj, void *p)
success: success:
Py_DECREF(index); Py_DECREF(index);
*(uid_t *)p = uid; *p = uid;
return 1; return 1;
underflow: underflow:
@ -778,7 +778,7 @@ fail:
} }
int int
_Py_Gid_Converter(PyObject *obj, void *p) _Py_Gid_Converter(PyObject *obj, gid_t *p)
{ {
gid_t gid; gid_t gid;
PyObject *index; PyObject *index;
@ -866,7 +866,7 @@ _Py_Gid_Converter(PyObject *obj, void *p)
success: success:
Py_DECREF(index); Py_DECREF(index);
*(gid_t *)p = gid; *p = gid;
return 1; return 1;
underflow: underflow:

View File

@ -14,8 +14,8 @@ extern "C" {
#ifndef MS_WINDOWS #ifndef MS_WINDOWS
PyAPI_FUNC(PyObject *) _PyLong_FromUid(uid_t); PyAPI_FUNC(PyObject *) _PyLong_FromUid(uid_t);
PyAPI_FUNC(PyObject *) _PyLong_FromGid(gid_t); PyAPI_FUNC(PyObject *) _PyLong_FromGid(gid_t);
PyAPI_FUNC(int) _Py_Uid_Converter(PyObject *, void *); PyAPI_FUNC(int) _Py_Uid_Converter(PyObject *, uid_t *);
PyAPI_FUNC(int) _Py_Gid_Converter(PyObject *, void *); PyAPI_FUNC(int) _Py_Gid_Converter(PyObject *, gid_t *);
#endif /* MS_WINDOWS */ #endif /* MS_WINDOWS */
#if defined(PYPTHREAD_SIGMASK) || defined(HAVE_SIGWAIT) || \ #if defined(PYPTHREAD_SIGMASK) || defined(HAVE_SIGWAIT) || \