Skip to content

Commit 3966e2e

Browse files
bpo-42655: Fix subprocess extra_groups gid conversion (pythonGH-23762)
(cherry picked from commit 0159e5e) Co-authored-by: Jakub Kulík <Kulikjak@gmail.com>
1 parent cc7f745 commit 3966e2e

4 files changed

Lines changed: 9 additions & 11 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`subprocess` *extra_groups* is now correctly passed into setgroups()
2+
system call.

Modules/_posixsubprocess.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
753753
if (groups_list != Py_None) {
754754
#ifdef HAVE_SETGROUPS
755755
Py_ssize_t i;
756-
unsigned long gid;
756+
gid_t gid;
757757

758758
if (!PyList_Check(groups_list)) {
759759
PyErr_SetString(PyExc_TypeError,
@@ -787,10 +787,6 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
787787
Py_DECREF(elem);
788788
goto cleanup;
789789
} else {
790-
/* In posixmodule.c UnsignedLong is used as a fallback value
791-
* if the value provided does not fit in a Long. Since we are
792-
* already doing the bounds checking on the Python side, we
793-
* can go directly to an UnsignedLong here. */
794790
if (!_Py_Gid_Converter(elem, &gid)) {
795791
Py_DECREF(elem);
796792
PyErr_SetString(PyExc_ValueError, "invalid group id");

Modules/posixmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ _PyLong_FromGid(gid_t gid)
632632
}
633633

634634
int
635-
_Py_Uid_Converter(PyObject *obj, void *p)
635+
_Py_Uid_Converter(PyObject *obj, uid_t *p)
636636
{
637637
uid_t uid;
638638
PyObject *index;
@@ -719,7 +719,7 @@ _Py_Uid_Converter(PyObject *obj, void *p)
719719

720720
success:
721721
Py_DECREF(index);
722-
*(uid_t *)p = uid;
722+
*p = uid;
723723
return 1;
724724

725725
underflow:
@@ -738,7 +738,7 @@ _Py_Uid_Converter(PyObject *obj, void *p)
738738
}
739739

740740
int
741-
_Py_Gid_Converter(PyObject *obj, void *p)
741+
_Py_Gid_Converter(PyObject *obj, gid_t *p)
742742
{
743743
gid_t gid;
744744
PyObject *index;
@@ -826,7 +826,7 @@ _Py_Gid_Converter(PyObject *obj, void *p)
826826

827827
success:
828828
Py_DECREF(index);
829-
*(gid_t *)p = gid;
829+
*p = gid;
830830
return 1;
831831

832832
underflow:

Modules/posixmodule.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ extern "C" {
1414
#ifndef MS_WINDOWS
1515
PyAPI_FUNC(PyObject *) _PyLong_FromUid(uid_t);
1616
PyAPI_FUNC(PyObject *) _PyLong_FromGid(gid_t);
17-
PyAPI_FUNC(int) _Py_Uid_Converter(PyObject *, void *);
18-
PyAPI_FUNC(int) _Py_Gid_Converter(PyObject *, void *);
17+
PyAPI_FUNC(int) _Py_Uid_Converter(PyObject *, uid_t *);
18+
PyAPI_FUNC(int) _Py_Gid_Converter(PyObject *, gid_t *);
1919
#endif /* MS_WINDOWS */
2020

2121
#if defined(PYPTHREAD_SIGMASK) || defined(HAVE_SIGWAIT) || \

0 commit comments

Comments
 (0)