xkbcomp: escape the section names before storing them in the keymap
authorRan Benita <ran234@gmail.com>
Thu, 18 Jul 2013 11:50:21 +0000 (14:50 +0300)
committerRan Benita <ran234@gmail.com>
Thu, 18 Jul 2013 11:50:21 +0000 (14:50 +0300)
This ensures the names are escaped before having any interaction with
the user.

This was caught by noticing dump(compile(dump())) != dump. Since that's
a nice test we add it to stringcomp.

https://bugs.freedesktop.org/show_bug.cgi?id=67032

Reported-By: Auke Booij
Signed-off-by: Ran Benita <ran234@gmail.com>
src/xkbcomp/ast-build.c
src/xkbcomp/compat.c
src/xkbcomp/keycodes.c
src/xkbcomp/symbols.c
src/xkbcomp/types.c
src/xkbcomp/xkbcomp-priv.h
test/stringcomp.c

index c9b7cb0..4a36802 100644 (file)
@@ -464,8 +464,8 @@ err:
     return NULL;
 }
 
-static void
-EscapeMapName(char *name)
+void
+XkbEscapeMapName(char *name)
 {
     /*
      * All latin-1 alphanumerics, plus parens, slash, minus, underscore and
@@ -498,7 +498,7 @@ XkbFileCreate(struct xkb_context *ctx, enum xkb_file_type type, char *name,
     if (!file)
         return NULL;
 
-    EscapeMapName(name);
+    XkbEscapeMapName(name);
     file->file_type = type;
     file->topName = strdup_safe(name);
     file->name = name;
index 5682895..3a14dc6 100644 (file)
@@ -1025,6 +1025,7 @@ static bool
 CopyCompatToKeymap(struct xkb_keymap *keymap, CompatInfo *info)
 {
     keymap->compat_section_name = strdup_safe(info->name);
+    XkbEscapeMapName(keymap->compat_section_name);
 
     if (!darray_empty(info->interps)) {
         /* Most specific to least specific. */
index edc54c9..44e11bc 100644 (file)
@@ -604,6 +604,7 @@ CopyKeyNamesToKeymap(struct xkb_keymap *keymap, KeyNamesInfo *info)
     unsigned i;
 
     keymap->keycodes_section_name = strdup_safe(info->name);
+    XkbEscapeMapName(keymap->keycodes_section_name);
 
     keymap->min_key_code = info->min_key_code;
     keymap->max_key_code = info->max_key_code;
index a2970f5..f08c204 100644 (file)
@@ -1573,6 +1573,7 @@ CopySymbolsToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info)
     struct xkb_key *key;
 
     keymap->symbols_section_name = strdup_safe(info->name);
+    XkbEscapeMapName(keymap->symbols_section_name);
 
     keymap->num_group_names = darray_size(info->group_names);
     keymap->group_names = darray_mem(info->group_names, 0);
index 1eb1b73..c6a2672 100644 (file)
@@ -775,6 +775,7 @@ static bool
 CopyKeyTypesToKeymap(struct xkb_keymap *keymap, KeyTypesInfo *info)
 {
     keymap->types_section_name = strdup_safe(info->name);
+    XkbEscapeMapName(keymap->types_section_name);
 
     keymap->num_types = darray_size(info->types);
     if (keymap->num_types == 0)
index 97cc2a8..a5d4a1e 100644 (file)
@@ -56,6 +56,9 @@ XkbFile *
 XkbFileFromComponents(struct xkb_context *ctx,
                       const struct xkb_component_names *kkctgs);
 
+void
+XkbEscapeMapName(char *name);
+
 bool
 CompileKeycodes(XkbFile *file, struct xkb_keymap *keymap,
                 enum merge_mode merge);
index 3aefba9..1a1813b 100644 (file)
@@ -34,7 +34,7 @@ main(int argc, char *argv[])
 {
     struct xkb_context *ctx = test_get_context(0);
     struct xkb_keymap *keymap;
-    char *original, *dump;
+    char *original, *dump, *dump2;
 
     assert(ctx);
 
@@ -81,6 +81,10 @@ main(int argc, char *argv[])
     xkb_keymap_unref(keymap);
     keymap = test_compile_string(ctx, dump);
     assert(keymap);
+    /* Now test that the dump of the dump is equal to the dump! */
+    dump2 = xkb_keymap_get_as_string(keymap, XKB_KEYMAP_USE_ORIGINAL_FORMAT);
+    assert(dump2);
+    assert(streq(dump, dump2));
 
     /* Test response to invalid formats and flags. */
     assert(!xkb_keymap_new_from_string(ctx, dump, 0, 0));
@@ -93,6 +97,7 @@ main(int argc, char *argv[])
 
     xkb_keymap_unref(keymap);
     free(dump);
+    free(dump2);
 
     xkb_context_unref(ctx);