Skip to content

Commit

Permalink
Make posix_openpt fd is non-inheritable.
Browse files Browse the repository at this point in the history
By default all fds returned by Python APIs must be non-inheritable.
  • Loading branch information
gpshead committed May 19, 2023
1 parent c99e91b commit f6dcd54
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -8060,9 +8060,21 @@ os_posix_openpt_impl(PyObject *module, int oflag)
{
int fd;

#if defined(O_CLOEXEC)
oflag |= O_CLOEXEC;
#endif

fd = posix_openpt(oflag);
if (fd == -1)
if (fd == -1) {
posix_error();
return -1;
}

// Just in case, likely a no-op given O_CLOEXEC above.
if (_Py_set_inheritable(fd, 0, NULL) < 0) {
close(fd);
return -1;
}

return fd;
}
Expand Down

0 comments on commit f6dcd54

Please sign in to comment.