Blame SOURCES/0008-xkbcomp-fix-crashes-in-the-parser-when-geometry-toke.patch

a2d0a1
From 6fa9f581eda2bc790937f347df4976f02d45240b Mon Sep 17 00:00:00 2001
a2d0a1
From: Ran Benita <ran234@gmail.com>
a2d0a1
Date: Sat, 10 Mar 2018 23:32:12 +0200
a2d0a1
Subject: [PATCH 08/10] xkbcomp: fix crashes in the parser when geometry tokens
a2d0a1
 appear
a2d0a1
a2d0a1
In the XKB format, floats and various keywords can only be used in the
a2d0a1
xkb_geometry section. xkbcommon removed support xkb_geometry, but still
a2d0a1
parses it for backward compatibility. As part of ignoring it, the float
a2d0a1
AST node and various keywords were removed, and instead NULL was
a2d0a1
returned by their parsing actions. However, the rest of the code does
a2d0a1
not handle NULLs, and so when they appear crashes usually ensue.
a2d0a1
a2d0a1
To fix this, restore the float AST node and the ignored keywords. None
a2d0a1
of the evaluating code expects them, so nice error are displayed.
a2d0a1
a2d0a1
Caught with the afl fuzzer.
a2d0a1
a2d0a1
Signed-off-by: Ran Benita <ran234@gmail.com>
a2d0a1
(cherry picked from commit e3cacae7b1bfda0d839c280494f23284a1187adf)
a2d0a1
---
a2d0a1
 src/xkbcomp/ast-build.c |  8 ++++++++
a2d0a1
 src/xkbcomp/ast-build.h |  3 +++
a2d0a1
 src/xkbcomp/ast.h       |  7 +++++++
a2d0a1
 src/xkbcomp/parser.y    | 10 +++++-----
a2d0a1
 4 files changed, 23 insertions(+), 5 deletions(-)
a2d0a1
a2d0a1
diff --git a/src/xkbcomp/ast-build.c b/src/xkbcomp/ast-build.c
a2d0a1
index b5e5616..c3e3279 100644
a2d0a1
--- a/src/xkbcomp/ast-build.c
a2d0a1
+++ b/src/xkbcomp/ast-build.c
a2d0a1
@@ -105,6 +105,13 @@ ExprCreateInteger(int ival)
a2d0a1
     return expr;
a2d0a1
 }
a2d0a1
a2d0a1
+ExprDef *
a2d0a1
+ExprCreateFloat(void)
a2d0a1
+{
a2d0a1
+    EXPR_CREATE(ExprFloat, expr, EXPR_VALUE, EXPR_TYPE_FLOAT);
a2d0a1
+    return expr;
a2d0a1
+}
a2d0a1
+
a2d0a1
 ExprDef *
a2d0a1
 ExprCreateBoolean(bool set)
a2d0a1
 {
a2d0a1
@@ -785,6 +792,7 @@ static const char *expr_value_type_strings[_EXPR_TYPE_NUM_VALUES] = {
a2d0a1
     [EXPR_TYPE_UNKNOWN] = "unknown",
a2d0a1
     [EXPR_TYPE_BOOLEAN] = "boolean",
a2d0a1
     [EXPR_TYPE_INT] = "int",
a2d0a1
+    [EXPR_TYPE_FLOAT] = "float",
a2d0a1
     [EXPR_TYPE_STRING] = "string",
a2d0a1
     [EXPR_TYPE_ACTION] = "action",
a2d0a1
     [EXPR_TYPE_KEYNAME] = "keyname",
a2d0a1
diff --git a/src/xkbcomp/ast-build.h b/src/xkbcomp/ast-build.h
a2d0a1
index b57e4cd..6c76f38 100644
a2d0a1
--- a/src/xkbcomp/ast-build.h
a2d0a1
+++ b/src/xkbcomp/ast-build.h
a2d0a1
@@ -36,6 +36,9 @@ ExprCreateString(xkb_atom_t str);
a2d0a1
 ExprDef *
a2d0a1
 ExprCreateInteger(int ival);
a2d0a1
a2d0a1
+ExprDef *
a2d0a1
+ExprCreateFloat(void);
a2d0a1
+
a2d0a1
 ExprDef *
a2d0a1
 ExprCreateBoolean(bool set);
a2d0a1
a2d0a1
diff --git a/src/xkbcomp/ast.h b/src/xkbcomp/ast.h
a2d0a1
index 9778884..49c5ada 100644
a2d0a1
--- a/src/xkbcomp/ast.h
a2d0a1
+++ b/src/xkbcomp/ast.h
a2d0a1
@@ -95,6 +95,7 @@ enum expr_value_type {
a2d0a1
     EXPR_TYPE_UNKNOWN = 0,
a2d0a1
     EXPR_TYPE_BOOLEAN,
a2d0a1
     EXPR_TYPE_INT,
a2d0a1
+    EXPR_TYPE_FLOAT,
a2d0a1
     EXPR_TYPE_STRING,
a2d0a1
     EXPR_TYPE_ACTION,
a2d0a1
     EXPR_TYPE_KEYNAME,
a2d0a1
@@ -186,6 +187,12 @@ typedef struct {
a2d0a1
     int ival;
a2d0a1
 } ExprInteger;
a2d0a1
a2d0a1
+typedef struct {
a2d0a1
+    ExprCommon expr;
a2d0a1
+    /* We don't support floats, but we still represnt them in the AST, in
a2d0a1
+     * order to provide proper error messages. */
a2d0a1
+} ExprFloat;
a2d0a1
+
a2d0a1
 typedef struct {
a2d0a1
     ExprCommon expr;
a2d0a1
     xkb_atom_t key_name;
a2d0a1
diff --git a/src/xkbcomp/parser.y b/src/xkbcomp/parser.y
a2d0a1
index cedb8fa..bda7f64 100644
a2d0a1
--- a/src/xkbcomp/parser.y
a2d0a1
+++ b/src/xkbcomp/parser.y
a2d0a1
@@ -584,13 +584,13 @@ Element         :       ACTION_TOK
a2d0a1
                 |       INDICATOR
a2d0a1
                         { $$ = xkb_atom_intern_literal(param->ctx, "indicator"); }
a2d0a1
                 |       SHAPE
a2d0a1
-                        { $$ = XKB_ATOM_NONE; }
a2d0a1
+                        { $$ = xkb_atom_intern_literal(param->ctx, "shape"); }
a2d0a1
                 |       ROW
a2d0a1
-                        { $$ = XKB_ATOM_NONE; }
a2d0a1
+                        { $$ = xkb_atom_intern_literal(param->ctx, "row"); }
a2d0a1
                 |       SECTION
a2d0a1
-                        { $$ = XKB_ATOM_NONE; }
a2d0a1
+                        { $$ = xkb_atom_intern_literal(param->ctx, "section"); }
a2d0a1
                 |       TEXT
a2d0a1
-                        { $$ = XKB_ATOM_NONE; }
a2d0a1
+                        { $$ = xkb_atom_intern_literal(param->ctx, "text"); }
a2d0a1
                 ;
a2d0a1
a2d0a1
 OptMergeMode    :       MergeMode       { $$ = $1; }
a2d0a1
@@ -680,7 +680,7 @@ Terminal        :       String
a2d0a1
                 |       Integer
a2d0a1
                         { $$ = ExprCreateInteger($1); }
a2d0a1
                 |       Float
a2d0a1
-                        { $$ = NULL; }
a2d0a1
+                        { $$ = ExprCreateFloat(/* Discard $1 */); }
a2d0a1
                 |       KEYNAME
a2d0a1
                         { $$ = ExprCreateKeyName($1); }
a2d0a1
                 ;
a2d0a1
--
a2d0a1
2.20.1