mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-11-04 18:18:56 +01:00
gutils: Fix a leak when user-dirs.dirs declares a variable twice
Found by the oss-fuzz test for this parser, `fuzzing/fuzz_special_dirs.c`. Signed-off-by: Philip Withnall <pwithnall@gnome.org> oss-fuzz#445870121 oss-fuzz#445848222
This commit is contained in:
@@ -126,10 +126,15 @@ load_user_special_dirs_from_string (const gchar *string, const gchar *home_dir,
|
|||||||
for (len = strlen (d); len > 1 && d[len - 1] == '/'; len--)
|
for (len = strlen (d); len > 1 && d[len - 1] == '/'; len--)
|
||||||
d[len - 1] = 0;
|
d[len - 1] = 0;
|
||||||
|
|
||||||
|
/* Duplicates override the previous value. This is not explicit in the
|
||||||
|
* spec, but given that the spec[1] is designed to allow user-dirs.dirs to
|
||||||
|
* be sourced in a shell, overriding is the behaviour that would imply.
|
||||||
|
*
|
||||||
|
* [1]: https://www.freedesktop.org/wiki/Software/xdg-user-dirs/ */
|
||||||
|
g_clear_pointer (&special_dirs[directory], g_free);
|
||||||
|
|
||||||
if (is_relative)
|
if (is_relative)
|
||||||
{
|
|
||||||
special_dirs[directory] = g_build_filename (home_dir, d, NULL);
|
special_dirs[directory] = g_build_filename (home_dir, d, NULL);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
special_dirs[directory] = g_strdup (d);
|
special_dirs[directory] = g_strdup (d);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -871,6 +871,7 @@ test_user_special_dirs_load_unlocked (void)
|
|||||||
"XDG_DOCUMENTS_DIR = \"$HOME\"\n"
|
"XDG_DOCUMENTS_DIR = \"$HOME\"\n"
|
||||||
"XDG_DOWNLOAD_DIR = \"$HOME/Downloads\"\n"
|
"XDG_DOWNLOAD_DIR = \"$HOME/Downloads\"\n"
|
||||||
"XDG_MUSIC_DIR = \"///\"\n"
|
"XDG_MUSIC_DIR = \"///\"\n"
|
||||||
|
"XDG_PICTURES_DIR = \"$HOME/Pictures\"\n"
|
||||||
"XDG_PICTURES_DIR = \"/\"\nXDG_DOWNLOAD_DIR = \"/dev/null\n",
|
"XDG_PICTURES_DIR = \"/\"\nXDG_DOWNLOAD_DIR = \"/dev/null\n",
|
||||||
-1, NULL);
|
-1, NULL);
|
||||||
g_assert_true (result);
|
g_assert_true (result);
|
||||||
|
|||||||
Reference in New Issue
Block a user