Commit 90f04e042b776eda656440ca9ac49af05d86196f

Daniel Stone 2012-02-20T18:07:29

Perform bounds checking in ExprResolveLevel Both callers perform the same bounds check, so move it into ExprResolveLevel itself. Signed-off-by: Daniel Stone <daniel@fooishbar.org>

diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c
index 929548a..c0c4c6f 100644
--- a/src/xkbcomp/expr.c
+++ b/src/xkbcomp/expr.c
@@ -673,6 +673,7 @@ int
 ExprResolveLevel(ExprDef * expr,
                  ExprResult * val_rtrn)
 {
+    int ret;
     static LookupEntry level_names[] = {
         { "level1", 1 },
         { "level2", 2 },
@@ -685,8 +686,17 @@ ExprResolveLevel(ExprDef * expr,
         { NULL, 0 }
     };
 
-    return ExprResolveIntegerLookup(expr, val_rtrn, SimpleLookup,
-                                    level_names);
+    ret = ExprResolveIntegerLookup(expr, val_rtrn, SimpleLookup, level_names);
+    if (ret == False)
+        return ret;
+
+    if (val_rtrn->ival < 1 || val_rtrn->ival > XkbMaxShiftLevel) {
+        ERROR("Shift level %d is out of range (1..%d)\n", val_rtrn->ival,
+              XkbMaxShiftLevel);
+        return False;
+    }
+
+    return True;
 }
 
 int
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index 57164d2..f516276 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -679,14 +679,6 @@ SetMapEntry(KeyTypeInfo * type,
         ACTION("Ignoring malformed level specification\n");
         return False;
     }
-    if ((rtrn.ival < 1) || (rtrn.ival > XkbMaxShiftLevel + 1))
-    {
-        ERROR("Shift level %d out of range (1..%d) in key type %s\n",
-               XkbMaxShiftLevel + 1, rtrn.ival, TypeTxt(type));
-        ACTION("Ignoring illegal definition of map[%s]\n",
-                MapEntryTxt(xkb, &entry));
-        return False;
-    }
     entry.level = rtrn.ival - 1;
     return AddMapEntry(xkb, type, &entry, True, True);
 }
@@ -811,15 +803,6 @@ SetLevelName(KeyTypeInfo * type, ExprDef * arrayNdx, ExprDef * value)
         return ReportTypeShouldBeArray(type, "level name");
     if (!ExprResolveLevel(arrayNdx, &rtrn))
         return ReportTypeBadType(type, "level name", "integer");
-    if ((rtrn.ival < 1) || (rtrn.ival > XkbMaxShiftLevel + 1))
-    {
-        ERROR("Level name %d out of range (1..%d) in key type %s\n",
-               rtrn.ival,
-               XkbMaxShiftLevel + 1,
-               XkbcAtomText(type->name));
-        ACTION("Ignoring illegal level name definition\n");
-        return False;
-    }
     level = rtrn.ival - 1;
     if (!ExprResolveString(value, &rtrn))
     {