BugĀ 620496 - schema compiler: reject invalid paths
authorRyan Lortie <desrt@desrt.ca>
Mon, 7 Jun 2010 08:18:43 +0000 (10:18 +0200)
committerRyan Lortie <desrt@desrt.ca>
Mon, 7 Jun 2010 08:18:43 +0000 (10:18 +0200)
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
gio/tests/gschema-compile.c
gio/tests/schema-tests/invalid-path.gschema.xml [new file with mode: 0644]

index 42d056b..95f7582 100644 (file)
@@ -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,
index 3ea0e97..9201abd 100644 (file)
@@ -57,6 +57,7 @@ static const SchemaTest tests[] = {
   { "default-not-in-choices",       NULL, "*<default> contains string not in <choices>*"        },
   { "array-default-not-in-choices", NULL, "*<default> contains string not in <choices>*"        },
   { "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 (file)
index 0000000..85ecd4c
--- /dev/null
@@ -0,0 +1,3 @@
+<schemalist>
+  <schema id='invalid-path' path='/app/myapp'/>
+</schemalist>