Skip to content

Commit

Permalink
linux: Open files with O_CLOEXEC to not leak fds to child processes (
Browse files Browse the repository at this point in the history
…signal11#446)

Motivation described here: libusb/hidapi#446
  • Loading branch information
ids1024 authored Aug 21, 2022
1 parent 15a7114 commit dbd1681
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions linux/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ static int get_hid_report_descriptor(const char *rpt_path, struct hidraw_report_
int rpt_handle;
ssize_t res;

rpt_handle = open(rpt_path, O_RDONLY);
rpt_handle = open(rpt_path, O_RDONLY | O_CLOEXEC);
if (rpt_handle < 0) {
register_global_error_format("open failed (%s): %s", rpt_path, strerror(errno));
return -1;
Expand Down Expand Up @@ -473,7 +473,7 @@ static int parse_hid_vid_pid_from_uevent_path(const char *uevent_path, unsigned
int handle;
ssize_t res;

handle = open(uevent_path, O_RDONLY);
handle = open(uevent_path, O_RDONLY | O_CLOEXEC);
if (handle < 0) {
register_global_error_format("open failed (%s): %s", uevent_path, strerror(errno));
return 0;
Expand Down Expand Up @@ -981,7 +981,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)

dev = new_hid_device();

dev->device_handle = open(path, O_RDWR);
dev->device_handle = open(path, O_RDWR | O_CLOEXEC);

/* If we have a good handle, return it. */
if (dev->device_handle >= 0) {
Expand Down

0 comments on commit dbd1681

Please sign in to comment.