mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-03 09:46:17 +01:00
glocalfile: Check g_stat() return value
There were a couple of places where the return value wasn’t checked, and hence failure could not be noticed. Coverity CIDs: #1159435, #1159426 Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
parent
9a519c8bf0
commit
24b5d86d4a
@ -1824,6 +1824,7 @@ _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev)
|
||||
{
|
||||
static gsize home_dev_set = 0;
|
||||
static dev_t home_dev;
|
||||
static gboolean home_dev_valid = FALSE;
|
||||
char *topdir, *globaldir, *trashdir, *tmpname;
|
||||
uid_t uid;
|
||||
char uid_str[32];
|
||||
@ -1834,13 +1835,23 @@ _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev)
|
||||
{
|
||||
GStatBuf home_stat;
|
||||
|
||||
g_stat (g_get_home_dir (), &home_stat);
|
||||
home_dev = home_stat.st_dev;
|
||||
if (g_stat (g_get_home_dir (), &home_stat) == 0)
|
||||
{
|
||||
home_dev = home_stat.st_dev;
|
||||
home_dev_valid = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
home_dev_valid = FALSE;
|
||||
}
|
||||
|
||||
g_once_init_leave (&home_dev_set, 1);
|
||||
}
|
||||
|
||||
/* Assume we can trash to the home */
|
||||
if (dir_dev == home_dev)
|
||||
if (!home_dev_valid)
|
||||
return FALSE;
|
||||
else if (dir_dev == home_dev)
|
||||
return TRUE;
|
||||
|
||||
topdir = find_mountpoint_for (dirname, dir_dev, TRUE);
|
||||
@ -1972,7 +1983,15 @@ g_local_file_trash (GFile *file,
|
||||
}
|
||||
|
||||
homedir = g_get_home_dir ();
|
||||
g_stat (homedir, &home_stat);
|
||||
if (g_stat (homedir, &home_stat) != 0)
|
||||
{
|
||||
errsv = errno;
|
||||
|
||||
g_set_io_error (error,
|
||||
_("Error trashing file %s: %s"),
|
||||
file, errsv);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
is_homedir_trash = FALSE;
|
||||
trashdir = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user