From 0e4641adfdaf74b366aded06fa584d81532f5954 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Mon, 27 Mar 2023 16:57:10 -0700 Subject: Set close-on-exec when opening files Signed-off-by: Alan Coopersmith --- src/MultiSrc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/MultiSrc.c') diff --git a/src/MultiSrc.c b/src/MultiSrc.c index 22d9c16..df85339 100644 --- a/src/MultiSrc.c +++ b/src/MultiSrc.c @@ -76,6 +76,13 @@ in this Software without prior written authorization from the X Consortium. #include #include +#ifdef O_CLOEXEC +#define FOPEN_CLOEXEC "e" +#else +#define FOPEN_CLOEXEC "" +#define O_CLOEXEC 0 +#endif + /**************************************************************** * * Full class record constant @@ -966,7 +973,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, sizeof(unsigned char) * strlen(string)) == -1) @@ -1084,7 +1091,7 @@ InitStringOrFile(MultiSrcObject src, Boolean newString) XtErrorMsg("NoFile", "multiSourceCreate", "XawError", "Creating a read only disk widget and no file specified.", NULL, 0); - open_mode = "r"; + open_mode = "r" FOPEN_CLOEXEC; break; case XawtextAppend: case XawtextEdit: @@ -1097,9 +1104,9 @@ InitStringOrFile(MultiSrcObject src, Boolean newString) (void) tmpnam(src->multi_src.string); src->multi_src.is_tempfile = TRUE; - open_mode = "w"; + open_mode = "w" FOPEN_CLOEXEC; } else - open_mode = "r+"; + open_mode = "r+" FOPEN_CLOEXEC; break; default: XtErrorMsg("badMode", "multiSourceCreate", "XawError", -- cgit v1.2.3