From: Ryan Lortie Date: Wed, 23 Oct 2013 20:42:12 +0000 (-0400) Subject: GSettings: verify path validity on constructors X-Git-Tag: 2.39.0~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6568843624e9f46a3c51cd8c1a6670896a48f1fb;p=platform%2Fupstream%2Fglib.git GSettings: verify path validity on constructors Don't allow constructing GSettings objects with invalid paths. https://bugzilla.gnome.org/show_bug.cgi?id=704802 --- diff --git a/gio/gsettings.c b/gio/gsettings.c index 2f23f09..f31ad3f 100644 --- a/gio/gsettings.c +++ b/gio/gsettings.c @@ -866,6 +866,21 @@ g_settings_new (const gchar *schema_id) NULL); } +static gboolean +path_is_valid (const gchar *path) +{ + if (!path) + return FALSE; + + if (path[0] != '/') + return FALSE; + + if (!g_str_has_suffix (path, "/")) + return FALSE; + + return strstr (path, "//") == NULL; +} + /** * g_settings_new_with_path: * @schema_id: the id of the schema @@ -881,6 +896,10 @@ g_settings_new (const gchar *schema_id) * It is a programmer error to call this function for a schema that * has an explicitly specified path. * + * It is a programmer error if @path is not a valid path. A valid path + * begins and ends with '/' and does not contain two consecutive '/' + * characters. + * * Returns: a new #GSettings object * * Since: 2.26 @@ -890,7 +909,7 @@ g_settings_new_with_path (const gchar *schema_id, const gchar *path) { g_return_val_if_fail (schema_id != NULL, NULL); - g_return_val_if_fail (path != NULL, NULL); + g_return_val_if_fail (path_is_valid (path), NULL); return g_object_new (G_TYPE_SETTINGS, "schema-id", schema_id, @@ -952,7 +971,7 @@ g_settings_new_with_backend_and_path (const gchar *schema_id, { g_return_val_if_fail (schema_id != NULL, NULL); g_return_val_if_fail (G_IS_SETTINGS_BACKEND (backend), NULL); - g_return_val_if_fail (path != NULL, NULL); + g_return_val_if_fail (path_is_valid (path), NULL); return g_object_new (G_TYPE_SETTINGS, "schema-id", schema_id, @@ -1000,6 +1019,10 @@ g_settings_new_full (GSettingsSchema *schema, GSettingsBackend *backend, const gchar *path) { + g_return_val_if_fail (schema != NULL, NULL); + g_return_val_if_fail (backend == NULL || G_IS_SETTINGS_BACKEND (backend), NULL); + g_return_val_if_fail (path == NULL || path_is_valid (path), NULL); + return g_object_new (G_TYPE_SETTINGS, "settings-schema", schema, "backend", backend,