[COMMITTED] Use O_CLOEXEC in sysconf [BZ #26791]

Message ID 20201111112329.GA16678@aloka.lostca.se
State Committed
Commit d2d714b9fc02e4710d6dc769d8ec2c9dab0eb69a
Headers
Series [COMMITTED] Use O_CLOEXEC in sysconf [BZ #26791] |

Commit Message

Arjun Shankar Nov. 11, 2020, 11:23 a.m. UTC
  From: Maximilian Krüger<max@maxfragg.de>

If sysconf is used in multithreaded processes, various file descriptors
may leak due to missing O_CLOEXEC.  This commit adds the flag.
---
This patch came in as a bug report. I have built and tested it on x86_64 and
committed it to master since it is an obvious fix.

 sysdeps/unix/sysv/linux/sysconf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/sysdeps/unix/sysv/linux/sysconf.c b/sysdeps/unix/sysv/linux/sysconf.c
index 7958a74164..9c5a4cb1a4 100644
--- a/sysdeps/unix/sysv/linux/sysconf.c
+++ b/sysdeps/unix/sysv/linux/sysconf.c
@@ -81,7 +81,7 @@  __sysconf (int name)
 
   if (procfname != NULL)
     {
-      int fd = __open_nocancel (procfname, O_RDONLY);
+      int fd = __open_nocancel (procfname, O_RDONLY | O_CLOEXEC);
       if (fd != -1)
 	{
 	  /* This is more than enough, the file contains a single integer.  */