mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-11 23:16:14 +01:00
Merge branch '3090-resource-uri-malformed' into 'main'
gresourcefile: Fix crash if called with a badly escaped URI Closes #3090 See merge request GNOME/glib!3554
This commit is contained in:
commit
197e6d6f5d
@ -238,6 +238,7 @@ g_resource_file_new_for_path (const char *path)
|
||||
return G_FILE (resource);
|
||||
}
|
||||
|
||||
/* Will return %NULL if @uri is malformed */
|
||||
GFile *
|
||||
_g_resource_file_new (const char *uri)
|
||||
{
|
||||
@ -245,6 +246,9 @@ _g_resource_file_new (const char *uri)
|
||||
char *path;
|
||||
|
||||
path = g_uri_unescape_string (uri + strlen ("resource:"), NULL);
|
||||
if (path == NULL)
|
||||
return NULL;
|
||||
|
||||
resource = g_resource_file_new_for_path (path);
|
||||
g_free (path);
|
||||
|
||||
|
@ -108,18 +108,39 @@ test_local (void)
|
||||
gchar **schemes;
|
||||
|
||||
vfs = g_vfs_get_local ();
|
||||
g_assert (g_vfs_is_active (vfs));
|
||||
g_assert_true (g_vfs_is_active (vfs));
|
||||
|
||||
file = g_vfs_get_file_for_uri (vfs, "not a good uri");
|
||||
g_assert (G_IS_FILE (file));
|
||||
g_assert_true (G_IS_FILE (file));
|
||||
g_object_unref (file);
|
||||
|
||||
schemes = (gchar **)g_vfs_get_supported_uri_schemes (vfs);
|
||||
|
||||
g_assert (g_strv_length (schemes) > 0);
|
||||
g_assert_cmpuint (g_strv_length (schemes), >, 0);
|
||||
g_assert_cmpstr (schemes[0], ==, "file");
|
||||
}
|
||||
|
||||
static void
|
||||
test_resource_malformed_escaping (void)
|
||||
{
|
||||
GVfs *vfs;
|
||||
GFile *file;
|
||||
|
||||
g_test_bug ("https://gitlab.gnome.org/GNOME/glib/-/issues/3090");
|
||||
g_test_summary ("Test that g_vfs_get_file_for_uri() returns an invalid file for an invalid URI");
|
||||
|
||||
vfs = g_vfs_get_local ();
|
||||
g_assert_true (g_vfs_is_active (vfs));
|
||||
|
||||
file = g_vfs_get_file_for_uri (vfs, "resource:///%not-valid-escaping/gtk.css");
|
||||
g_assert_true (G_IS_FILE (file));
|
||||
|
||||
/* This only returns %NULL if the file was constructed with an invalid URI: */
|
||||
g_assert_null (g_file_get_uri_scheme (file));
|
||||
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
@ -127,6 +148,7 @@ main (int argc, char *argv[])
|
||||
|
||||
g_test_add_func ("/gvfs/local", test_local);
|
||||
g_test_add_func ("/gvfs/register-scheme", test_register_scheme);
|
||||
g_test_add_func ("/gvfs/resource/malformed-escaping", test_resource_malformed_escaping);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user