Use O_CLOEXEC in {g_,}open () calls for race-free setting of the close-on-exec flag

The remaining call sites are either Windows-only, between fork () and
exec () or in xdgmime copylib.

Hope I haven't missed any site.
This commit is contained in:
Maciej S. Szmigiero
2023-02-19 16:22:22 +01:00
committed by Philip Withnall
parent 0f5d274871
commit 3f2e18b07c
10 changed files with 56 additions and 24 deletions

View File

@@ -45,6 +45,10 @@
#include <io.h> /* For open() and close() prototypes. */
#endif
#ifndef O_CLOEXEC
#define O_CLOEXEC 0
#endif
#include "gmoduleconf.h"
#include "gstdio.h"
@@ -388,7 +392,7 @@ parse_libtool_archive (const gchar* libtool_name)
GTokenType token;
GScanner *scanner;
int fd = g_open (libtool_name, O_RDONLY, 0);
int fd = g_open (libtool_name, O_RDONLY | O_CLOEXEC, 0);
if (fd < 0)
{
gchar *display_libtool_name = g_filename_display_name (libtool_name);