parser: Do now allow the empty symbol declaration

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.
master
Yuichiro Hanada 2024-01-27 23:00:28 +09:00 committed by Wismill
parent 43c9752d44
commit efdb05d193
3 changed files with 11 additions and 1 deletions

View File

@ -465,7 +465,6 @@ SymbolsBody : SymbolsBody COMMA SymbolsVarDecl
{ $$.head = $1.head; $$.last->common.next = &$3->common; $$.last = $3; } { $$.head = $1.head; $$.last->common.next = &$3->common; $$.last = $3; }
| SymbolsVarDecl | SymbolsVarDecl
{ $$.head = $$.last = $1; } { $$.head = $$.last = $1; }
| { $$.head = $$.last = NULL; }
; ;
SymbolsVarDecl : Lhs EQUALS Expr { $$ = VarCreate($1, $3); } SymbolsVarDecl : Lhs EQUALS Expr { $$ = VarCreate($1, $3); }

View File

@ -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] };
};
};

View File

@ -54,6 +54,7 @@ main(void)
assert(!test_file(ctx, "keymaps/bad.xkb")); assert(!test_file(ctx, "keymaps/bad.xkb"));
assert(!test_file(ctx, "keymaps/syntax-error.xkb")); assert(!test_file(ctx, "keymaps/syntax-error.xkb"));
assert(!test_file(ctx, "keymaps/syntax-error2.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")); assert(!test_file(ctx, "does not exist"));
/* Test response to invalid flags and formats. */ /* Test response to invalid flags and formats. */