compose/parser: fix segfault when including The keysym cache for the new scanner was not initialized. To avoid such errors also in the future, require passing the priv argument in scanner_init(), instead of initializing it separately. Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
diff --git a/src/compose/parser.c b/src/compose/parser.c
index 9469aa4..51ad4ed 100644
--- a/src/compose/parser.c
+++ b/src/compose/parser.c
@@ -485,7 +485,7 @@ do_include(struct xkb_compose_table *table, struct scanner *s,
goto err_file;
}
- scanner_init(&new_s, table->ctx, string, size, path);
+ scanner_init(&new_s, table->ctx, string, size, path, s->priv);
ok = parse(table, &new_s, include_depth + 1);
if (!ok)
@@ -634,9 +634,8 @@ parse_string(struct xkb_compose_table *table, const char *string, size_t len,
{
struct scanner s;
struct keysym_from_name_cache cache;
- scanner_init(&s, table->ctx, string, len, file_name);
memset(&cache, 0, sizeof(cache));
- s.priv = &cache;
+ scanner_init(&s, table->ctx, string, len, file_name, &cache);
if (!parse(table, &s, 0))
return false;
/* Maybe the allocator can use the excess space. */
diff --git a/src/scanner-utils.h b/src/scanner-utils.h
index 914e11f..b60a100 100644
--- a/src/scanner-utils.h
+++ b/src/scanner-utils.h
@@ -71,7 +71,8 @@ struct scanner {
static inline void
scanner_init(struct scanner *s, struct xkb_context *ctx,
- const char *string, size_t len, const char *file_name)
+ const char *string, size_t len, const char *file_name,
+ void *priv)
{
s->s = string;
s->len = len;
@@ -80,6 +81,7 @@ scanner_init(struct scanner *s, struct xkb_context *ctx,
s->token_line = s->token_column = 1;
s->file_name = file_name;
s->ctx = ctx;
+ s->priv = priv;
}
static inline char
diff --git a/src/xkbcomp/rules.c b/src/xkbcomp/rules.c
index f4b475a..94ac547 100644
--- a/src/xkbcomp/rules.c
+++ b/src/xkbcomp/rules.c
@@ -828,7 +828,7 @@ matcher_match(struct matcher *m, const char *string, size_t len,
if (!m)
return false;
- scanner_init(&m->scanner, m->ctx, string, len, file_name);
+ scanner_init(&m->scanner, m->ctx, string, len, file_name, NULL);
initial:
switch (tok = gettok(m)) {
diff --git a/src/xkbcomp/scanner.c b/src/xkbcomp/scanner.c
index 8f24721..ba8f4e9 100644
--- a/src/xkbcomp/scanner.c
+++ b/src/xkbcomp/scanner.c
@@ -182,7 +182,7 @@ XkbParseString(struct xkb_context *ctx, const char *string, size_t len,
const char *file_name, const char *map)
{
struct scanner scanner;
- scanner_init(&scanner, ctx, string, len, file_name);
+ scanner_init(&scanner, ctx, string, len, file_name, NULL);
return parse(ctx, &scanner, map);
}