Commit a8f1a18b authored by Jehan's avatar Jehan

app: fix parent check for extension files.

I realize that g_file_has_parent() is only looking for the direct
parent. I want to look for any ancester, so I loop through parents (with
a limit to avoid infinite looping with symlinks and such).
parent 87b17944
......@@ -475,9 +475,13 @@ gimp_extension_validate_paths (GimpExtension *extension,
{
/* Note: appstream-glib is supposed to return everything as UTF-8,
* so we should not have to bother about this. */
gchar *path;
GFile *file;
GFile *ext_dir;
gchar *path;
GFile *file;
GFile *ext_dir;
GFile *parent;
GFile *child;
gboolean is_subpath = FALSE;
gint max_depth = 10;
if (g_path_is_absolute (patharray[i]))
{
......@@ -493,20 +497,35 @@ gimp_extension_validate_paths (GimpExtension *extension,
ext_dir = g_file_new_for_path (extension->p->path);
if (! g_file_has_parent (file, ext_dir))
/* Even with relative paths, it is easy to trick the system
* and leak out of the extension. So check actual kinship.
*/
child = g_object_ref (file);
while (max_depth > 0 && (parent = g_file_get_parent (child)))
{
if (g_file_equal (parent, ext_dir))
{
is_subpath = TRUE;
g_object_unref (parent);
break;
}
g_object_unref (child);
child = parent;
/* Avoid unfinite looping. */
max_depth--;
}
g_object_unref (child);
g_object_unref (ext_dir);
if (! is_subpath)
{
/* Even with relative paths, it is easy to trick the system
* and leak out of the extension. So check actual kinship.
*/
*error = g_error_new (GIMP_EXTENSION_ERROR,
GIMP_EXTENSION_BAD_PATH,
_("'%s' is not a child of the extension."),
patharray[i]);
g_object_unref (ext_dir);
g_object_unref (file);
break;
}
g_object_unref (ext_dir);
if (as_directories)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment