diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-03-28 12:08:41 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-03-28 12:10:58 -0700 |
commit | 324358180ddeaae482c5f66bb5647a4918710296 (patch) | |
tree | 19ff56ff256ec673a13b16d52b8264f064c0abf1 /src/MultiSrc.c | |
parent | 78eb3c75688a1e92ec435e5bc3ded063cd339a73 (diff) | |
download | xorg-lib-libXaw-324358180ddeaae482c5f66bb5647a4918710296.tar.gz |
Set close-on-exec when opening files
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'src/MultiSrc.c')
-rw-r--r-- | src/MultiSrc.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/MultiSrc.c b/src/MultiSrc.c index a9e84ba..5544b8b 100644 --- a/src/MultiSrc.c +++ b/src/MultiSrc.c @@ -75,6 +75,10 @@ in this Software without prior written authorization from The Open Group. #include <sys/stat.h> #include <fcntl.h> +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif + #define MAGIC_VALUE ((XawTextPosition)-1) #define streq(a, b) (strcmp((a), (b)) == 0) @@ -1089,7 +1093,7 @@ WriteToFile(String string, String name) int fd; Bool result = True; - if ((fd = creat(name, 0666)) == -1) + if ((fd = open(name, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0666)) == -1) return (False); if (write(fd, string, strlen(string)) == -1) @@ -1215,7 +1219,7 @@ InitStringOrFile(MultiSrcObject src, Bool newString) XtErrorMsg("NoFile", "multiSourceCreate", "XawError", "Creating a read only disk widget and no file specified.", NULL, 0); - open_mode = O_RDONLY; + open_mode = O_RDONLY | O_CLOEXEC; fdopen_mode = "r"; break; case XawtextAppend: @@ -1225,9 +1229,9 @@ InitStringOrFile(MultiSrcObject src, Bool newString) src->multi_src.is_tempfile = True; } else { -/* O_NOFOLLOW is a BSD & Linux extension */ +/* O_NOFOLLOW was a FreeBSD & Linux extension, now adopted by POSIX */ #ifdef O_NOFOLLOW - open_mode = O_RDWR | O_NOFOLLOW; + open_mode = O_RDWR | O_NOFOLLOW | O_CLOEXEC; #else open_mode = O_RDWR; /* unsafe; subject to race conditions */ #endif |