From 8ed0ff1381649fa58989904d39a4ee3339a35ab5 Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 27 Oct 2022 17:50:15 +0200 Subject: [PATCH] libc: Ensure /dev/random is opened with O_CLOEXEC on init --- libs/libc/src/init.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/libc/src/init.cpp b/libs/libc/src/init.cpp index 25800253..c62ea1dc 100644 --- a/libs/libc/src/init.cpp +++ b/libs/libc/src/init.cpp @@ -15,7 +15,8 @@ static void initialize_random() { unsigned int seed = 3735928559U; - FILE* fp = fopen("/dev/random", "rw"); + int fd = open("/dev/random", O_RDONLY | O_CLOEXEC); // If we somehow fail to close this file, close it on exec. + FILE* fp = fdopen(fd, "r"); if (!fp) { errno = 0;