From 71c5e3f899bf15c9dee09b36f146c5e72652d72b Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Mon, 7 Jun 2010 10:18:43 +0200 Subject: [PATCH] =?UTF-8?q?Bug=C2=A0620496=20-=20schema=20compiler:=20reje?= =?UTF-8?q?ct=20invalid=20paths?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The GSettings schema compiler was accepting any string as a path. It is probably quite a common mistake to suspect that '/apps/foo' is a valid path name when this will cause all sorts of trouble later. Check for this case and report the error. --- gio/gschema-compile.c | 16 ++++++++++++++-- gio/tests/gschema-compile.c | 1 + gio/tests/schema-tests/invalid-path.gschema.xml | 3 +++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 gio/tests/schema-tests/invalid-path.gschema.xml diff --git a/gio/gschema-compile.c b/gio/gschema-compile.c index 42d056b72..95f75822b 100644 --- a/gio/gschema-compile.c +++ b/gio/gschema-compile.c @@ -232,8 +232,20 @@ start_element (GMarkupParseContext *context, state->schema_root = gvdb_hash_table_insert (state->schema, ""); if (path != NULL) - gvdb_hash_table_insert_string (state->schema, - ".path", path); + { + if (!g_str_has_prefix (path, "/") || + !g_str_has_suffix (path, "/")) + { + g_set_error (error, G_MARKUP_ERROR, + G_MARKUP_ERROR_INVALID_CONTENT, + "a path, if given, must begin and " + "end with a slash"); + return; + } + + gvdb_hash_table_insert_string (state->schema, + ".path", path); + } } else g_set_error (error, G_MARKUP_ERROR, diff --git a/gio/tests/gschema-compile.c b/gio/tests/gschema-compile.c index 3ea0e978a..9201abd8e 100644 --- a/gio/tests/gschema-compile.c +++ b/gio/tests/gschema-compile.c @@ -57,6 +57,7 @@ static const SchemaTest tests[] = { { "default-not-in-choices", NULL, "* contains string not in *" }, { "array-default-not-in-choices", NULL, "* contains string not in *" }, { "bad-key", NULL, "*invalid name*" }, + { "invalid-path", NULL, "*must begin and end with a slash*" }, { "bad-key", "--allow-any-name", NULL }, { "bad-key2", NULL, "*invalid name*" }, { "bad-key2", "--allow-any-name", NULL }, diff --git a/gio/tests/schema-tests/invalid-path.gschema.xml b/gio/tests/schema-tests/invalid-path.gschema.xml new file mode 100644 index 000000000..85ecd4ceb --- /dev/null +++ b/gio/tests/schema-tests/invalid-path.gschema.xml @@ -0,0 +1,3 @@ + + +