Skip to content

Commit 1e515d2

Browse files
committed
Close inherited file descriptors in child processes for security
1 parent ac1edd4 commit 1e515d2

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/process.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ void process_start(int app_index)
8484
else if(pid == 0)
8585
{
8686
// Child process
87+
// Close inherited file descriptors (except stdin/stdout/stderr)
88+
int max_fd = (int)sysconf(_SC_OPEN_MAX);
89+
90+
if(max_fd < 0)
91+
{
92+
max_fd = 1024; // Fallback if sysconf fails
93+
}
94+
95+
for(int fd = 3; fd < max_fd; fd++)
96+
{
97+
close(fd);
98+
}
99+
87100
// Reset signals to default
88101
struct sigaction sa;
89102
sa.sa_handler = SIG_DFL;

0 commit comments

Comments
 (0)