summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-03-28 09:50:17 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-03-28 09:50:17 -0700
commit1e3fe79e3a5346bc2dbf8108afec1e69a42ff822 (patch)
tree3433b52e5001768b3963b06bcd0239aae20a0fbb
parent5b9d4d27a2b8441e966d701bf337ace848c4e4fd (diff)
downloadxorg-lib-libICE-1e3fe79e3a5346bc2dbf8108afec1e69a42ff822.tar.gz
Set close-on-exec when opening filesHEADmaster
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--src/ICElibint.h6
-rw-r--r--src/authutil.c5
-rw-r--r--src/getauth.c2
3 files changed, 10 insertions, 3 deletions
diff --git a/src/ICElibint.h b/src/ICElibint.h
index 3794085..00c15ca 100644
--- a/src/ICElibint.h
+++ b/src/ICElibint.h
@@ -43,6 +43,12 @@ Author: Ralph Mor, X Consortium
#include <stdlib.h>
#include <stddef.h>
+#ifdef O_CLOEXEC
+#define FOPEN_CLOEXEC "e"
+#else
+#define FOPEN_CLOEXEC ""
+#define O_CLOEXEC 0
+#endif
/*
* Vendor & Release
diff --git a/src/authutil.c b/src/authutil.c
index 86a716b..a47cf46 100644
--- a/src/authutil.c
+++ b/src/authutil.c
@@ -175,7 +175,8 @@ IceLockAuthFile (
{
if (creat_fd == -1)
{
- creat_fd = creat (creat_name, 0666);
+ creat_fd = open (creat_name,
+ O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0666);
if (creat_fd == -1)
{
@@ -347,7 +348,7 @@ IceGetAuthFileEntry (
if (access (filename, R_OK) != 0) /* checks REAL id */
return (NULL);
- if (!(auth_file = fopen (filename, "rb")))
+ if (!(auth_file = fopen (filename, "rb" FOPEN_CLOEXEC)))
return (NULL);
for (;;)
diff --git a/src/getauth.c b/src/getauth.c
index abd5644..b792e3e 100644
--- a/src/getauth.c
+++ b/src/getauth.c
@@ -146,7 +146,7 @@ _IceGetPoValidAuthIndices (
if (access (filename, R_OK) != 0) /* checks REAL id */
return;
- if (!(auth_file = fopen (filename, "rb")))
+ if (!(auth_file = fopen (filename, "rb" FOPEN_CLOEXEC)))
return;
for (;;)