mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 14:36:13 +01:00
g_mkstemp: Use O_CLOEXEC for race-free setting of the close-on-exec flag
mkstemp-like family of functions also use g_open () under the hood so they should pass the O_CLOEXEC flag there for race-free setting of the close-on-exec flag.
This commit is contained in:
parent
cbc15d6ceb
commit
8f8ebb1bd0
@ -1040,7 +1040,7 @@ handle_overwrite_open (const char *filename,
|
||||
tmp_filename = g_build_filename (dirname, ".goutputstream-XXXXXX", NULL);
|
||||
g_free (dirname);
|
||||
|
||||
tmpfd = g_mkstemp_full (tmp_filename, (readable ? O_RDWR : O_WRONLY) | O_BINARY, mode);
|
||||
tmpfd = g_mkstemp_full (tmp_filename, (readable ? O_RDWR : O_WRONLY) | O_BINARY | O_CLOEXEC, mode);
|
||||
if (tmpfd == -1)
|
||||
{
|
||||
g_free (tmp_filename);
|
||||
|
@ -1351,7 +1351,7 @@ g_file_set_contents_full (const gchar *filename,
|
||||
tmp_filename = g_strdup_printf ("%s.XXXXXX", filename);
|
||||
|
||||
errno = 0;
|
||||
fd = g_mkstemp_full (tmp_filename, O_RDWR | O_BINARY, mode);
|
||||
fd = g_mkstemp_full (tmp_filename, O_RDWR | O_BINARY | O_CLOEXEC, mode);
|
||||
|
||||
if (fd == -1)
|
||||
{
|
||||
@ -1704,7 +1704,7 @@ g_mkstemp_full (gchar *tmpl,
|
||||
gint
|
||||
g_mkstemp (gchar *tmpl)
|
||||
{
|
||||
return g_mkstemp_full (tmpl, O_RDWR | O_BINARY, 0600);
|
||||
return g_mkstemp_full (tmpl, O_RDWR | O_BINARY | O_CLOEXEC, 0600);
|
||||
}
|
||||
|
||||
static gint
|
||||
@ -1826,7 +1826,7 @@ g_file_open_tmp (const gchar *tmpl,
|
||||
|
||||
result = g_get_tmp_name (tmpl, &fulltemplate,
|
||||
wrap_g_open,
|
||||
O_CREAT | O_EXCL | O_RDWR | O_BINARY,
|
||||
O_CREAT | O_EXCL | O_RDWR | O_BINARY | O_CLOEXEC,
|
||||
0600,
|
||||
error);
|
||||
if (result != -1)
|
||||
|
Loading…
Reference in New Issue
Block a user