mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2026-10-24 00:49:00 +03:00
fileutils: Check the mode before creating the file
... so we don't create a file with elevated permissions if not
necessary.
This avoids a potential race where a temporary file is created with
higher priviliges than the result, which is technically a data leak.
Fixes: 45a36e52b5
This commit is contained in:
committed by
Philip Withnall
parent
0f0d7b7fab
commit
7f8c25086b
@@ -1362,9 +1362,13 @@ g_file_set_contents_full (const gchar *filename,
|
||||
GError *rename_error = NULL;
|
||||
gboolean retval;
|
||||
int fd;
|
||||
gboolean do_fsync;
|
||||
gboolean do_fsync, maintain_perms;
|
||||
GStatBuf old_stat;
|
||||
|
||||
maintain_perms = !g_stat (filename, &old_stat);
|
||||
if (maintain_perms)
|
||||
mode = 0600;
|
||||
|
||||
tmp_filename = g_strdup_printf ("%s.XXXXXX", filename);
|
||||
|
||||
errno = 0;
|
||||
@@ -1382,7 +1386,7 @@ g_file_set_contents_full (const gchar *filename,
|
||||
}
|
||||
|
||||
/* Maintain the permissions of the file if it exists */
|
||||
if (!g_stat (filename, &old_stat))
|
||||
if (maintain_perms)
|
||||
{
|
||||
#ifndef G_OS_WIN32
|
||||
if (fchmod (fd, old_stat.st_mode))
|
||||
|
||||
Reference in New Issue
Block a user