Skip to content

Commit f6dcd54

Browse files
committed
Make posix_openpt fd is non-inheritable.
By default all fds returned by Python APIs must be non-inheritable.
1 parent c99e91b commit f6dcd54

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Modules/posixmodule.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -8060,9 +8060,21 @@ os_posix_openpt_impl(PyObject *module, int oflag)
80608060
{
80618061
int fd;
80628062

8063+
#if defined(O_CLOEXEC)
8064+
oflag |= O_CLOEXEC;
8065+
#endif
8066+
80638067
fd = posix_openpt(oflag);
8064-
if (fd == -1)
8068+
if (fd == -1) {
80658069
posix_error();
8070+
return -1;
8071+
}
8072+
8073+
// Just in case, likely a no-op given O_CLOEXEC above.
8074+
if (_Py_set_inheritable(fd, 0, NULL) < 0) {
8075+
close(fd);
8076+
return -1;
8077+
}
80668078

80678079
return fd;
80688080
}

0 commit comments

Comments
 (0)