Skip to content

Commit

Permalink
parser: Do now allow the empty symbol declaration
Browse files Browse the repository at this point in the history
An empty element is allowed in SymbolsBody definition, so the following
keymap is gramatically correct.

```
xkb_keymap {
  ...
  xkb_symbols "sym" {
    key <SPC> {, [Space] };
  };
};
```

However, the current parser crashes with the keymap due to null pointer
access.
This change fixes it by changing the parser not to allow it.
  • Loading branch information
chiro authored and wismill committed Feb 5, 2024
1 parent 43c9752 commit efdb05d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/xkbcomp/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,6 @@ SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
{ $$.head = $1.head; $$.last->common.next = &$3->common; $$.last = $3; }
| SymbolsVarDecl
{ $$.head = $$.last = $1; }
| { $$.head = $$.last = NULL; }
;

SymbolsVarDecl : Lhs EQUALS Expr { $$ = VarCreate($1, $3); }
Expand Down
10 changes: 10 additions & 0 deletions test/data/keymaps/empty-symbol-decl.xkb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
xkb_keymap {
xkb_keycodes { include "evdev+aliases(qwerty)" };
xkb_types { include "complete" };
xkb_compat { include "complete" };
xkb_symbols "sym" {
// This syntax caused the crash in parser before, and is not accepted
// anymore.
key <SPC> { , [Space] };
};
};
1 change: 1 addition & 0 deletions test/filecomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ main(void)
assert(!test_file(ctx, "keymaps/bad.xkb"));
assert(!test_file(ctx, "keymaps/syntax-error.xkb"));
assert(!test_file(ctx, "keymaps/syntax-error2.xkb"));
assert(!test_file(ctx, "keymaps/empty-symbol-decl.xkb"));
assert(!test_file(ctx, "does not exist"));

/* Test response to invalid flags and formats. */
Expand Down

0 comments on commit efdb05d

Please sign in to comment.