Skip to content

Commit 0159e5e

Browse files
authored
bpo-42655: Fix subprocess extra_groups gid conversion (GH-23762)
1 parent dd39123 commit 0159e5e

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed
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
@@ -900,7 +900,7 @@ subprocess_fork_exec(PyObject *module, PyObject *args)
900900
if (groups_list != Py_None) {
901901
#ifdef HAVE_SETGROUPS
902902
Py_ssize_t i;
903-
unsigned long gid;
903+
gid_t gid;
904904

905905
if (!PyList_Check(groups_list)) {
906906
PyErr_SetString(PyExc_TypeError,
@@ -934,10 +934,6 @@ subprocess_fork_exec(PyObject *module, PyObject *args)
934934
Py_DECREF(elem);
935935
goto cleanup;
936936
} else {
937-
/* In posixmodule.c UnsignedLong is used as a fallback value
938-
* if the value provided does not fit in a Long. Since we are
939-
* already doing the bounds checking on the Python side, we
940-
* can go directly to an UnsignedLong here. */
941937
if (!_Py_Gid_Converter(elem, &gid)) {
942938
Py_DECREF(elem);
943939
PyErr_SetString(PyExc_ValueError, "invalid group id");

Modules/posixmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ _PyLong_FromGid(gid_t gid)
672672
}
673673

674674
int
675-
_Py_Uid_Converter(PyObject *obj, void *p)
675+
_Py_Uid_Converter(PyObject *obj, uid_t *p)
676676
{
677677
uid_t uid;
678678
PyObject *index;
@@ -759,7 +759,7 @@ _Py_Uid_Converter(PyObject *obj, void *p)
759759

760760
success:
761761
Py_DECREF(index);
762-
*(uid_t *)p = uid;
762+
*p = uid;
763763
return 1;
764764

765765
underflow:
@@ -778,7 +778,7 @@ _Py_Uid_Converter(PyObject *obj, void *p)
778778
}
779779

780780
int
781-
_Py_Gid_Converter(PyObject *obj, void *p)
781+
_Py_Gid_Converter(PyObject *obj, gid_t *p)
782782
{
783783
gid_t gid;
784784
PyObject *index;
@@ -866,7 +866,7 @@ _Py_Gid_Converter(PyObject *obj, void *p)
866866

867867
success:
868868
Py_DECREF(index);
869-
*(gid_t *)p = gid;
869+
*p = gid;
870870
return 1;
871871

872872
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)