Perform bounds checking in ExprResolveGroup

Every caller did the exact same check on the group bounds after calling
ExprResolveGroup, so might as well do it inside.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
master
Daniel Stone 2012-02-20 17:33:39 +00:00
parent 43ed3ff070
commit e209fe31df
3 changed files with 15 additions and 53 deletions

View File

@ -482,13 +482,6 @@ CheckGroupField(unsigned action,
if (!ExprResolveGroup(spec, &rtrn)) if (!ExprResolveGroup(spec, &rtrn))
return ReportMismatch(action, F_Group, "integer (range 1..8)"); return ReportMismatch(action, F_Group, "integer (range 1..8)");
if ((rtrn.ival < 1) || (rtrn.ival > XkbNumKbdGroups))
{
ERROR("Illegal group %d (must be in the range 1..%d)\n", rtrn.ival,
XkbNumKbdGroups);
ACTION("Action %s definition ignored\n", XkbcActionTypeText(action));
return False;
}
if (value->op == OpNegate) if (value->op == OpNegate)
*grp_rtrn = -rtrn.ival; *grp_rtrn = -rtrn.ival;
else if (value->op == OpUnaryPlus) else if (value->op == OpUnaryPlus)

View File

@ -643,6 +643,7 @@ int
ExprResolveGroup(ExprDef * expr, ExprResolveGroup(ExprDef * expr,
ExprResult * val_rtrn) ExprResult * val_rtrn)
{ {
int ret;
static LookupEntry group_names[] = { static LookupEntry group_names[] = {
{ "group1", 1 }, { "group1", 1 },
{ "group2", 2 }, { "group2", 2 },
@ -655,8 +656,17 @@ ExprResolveGroup(ExprDef * expr,
{ NULL, 0 } { NULL, 0 }
}; };
return ExprResolveIntegerLookup(expr, val_rtrn, SimpleLookup, ret = ExprResolveIntegerLookup(expr, val_rtrn, SimpleLookup, group_names);
group_names); if (ret == False)
return ret;
if (val_rtrn->uval == 0 || val_rtrn->uval > XkbNumKbdGroups) {
ERROR("Group index %d is out of range (1..%d)\n",
val_rtrn->uval, XkbNumKbdGroups);
return False;
}
return True;
} }
int int

View File

@ -904,13 +904,6 @@ GetGroupIndex(KeyInfo * key,
ACTION("Definition with non-integer array index ignored\n"); ACTION("Definition with non-integer array index ignored\n");
return False; return False;
} }
if ((tmp.uval < 1) || (tmp.uval > XkbNumKbdGroups))
{
ERROR("Group index for %s of key %s is out of range (1..%d)\n",
name, longText(key->name), XkbNumKbdGroups + 1);
ACTION("Ignoring %s for group %d\n", name, tmp.uval);
return False;
}
*ndx_rtrn = tmp.uval - 1; *ndx_rtrn = tmp.uval - 1;
return True; return True;
} }
@ -1131,15 +1124,6 @@ SetSymbolsField(KeyInfo * key,
free(tmp.str); free(tmp.str);
return False; return False;
} }
else if ((ndx.uval < 1) || (ndx.uval > XkbNumKbdGroups))
{
ERROR
("Group index for type of key %s is out of range (1..%d)\n",
longText(key->name), XkbNumKbdGroups + 1);
ACTION("Ignoring type for group %d\n", ndx.uval);
free(tmp.str);
return False;
}
else else
{ {
key->types[ndx.uval - 1] = xkb_intern_atom(tmp.str); key->types[ndx.uval - 1] = xkb_intern_atom(tmp.str);
@ -1337,13 +1321,6 @@ SetSymbolsField(KeyInfo * key,
ACTION("Definition with non-integer group ignored\n"); ACTION("Definition with non-integer group ignored\n");
return False; return False;
} }
if ((tmp.uval < 1) || (tmp.uval > XkbNumKbdGroups))
{
ERROR("Out-of-range (1..%d) group for redirect of key %s\n",
XkbNumKbdGroups, longText(key->name));
ERROR("Ignoring illegal group %d\n", tmp.uval);
return False;
}
key->groupInfo = key->groupInfo =
XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1); XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
key->defs.defined |= _Key_GroupInfo; key->defs.defined |= _Key_GroupInfo;
@ -1374,14 +1351,6 @@ SetGroupName(SymbolsInfo * info, ExprDef * arrayNdx, ExprDef * value)
ACTION("Definition with non-integer array index ignored\n"); ACTION("Definition with non-integer array index ignored\n");
return False; return False;
} }
if ((tmp.uval < 1) || (tmp.uval > XkbNumKbdGroups))
{
ERROR
("Attempt to specify name for illegal group (must be 1..%d)\n",
XkbNumKbdGroups + 1);
ACTION("Name for group %d ignored\n", tmp.uval);
return False;
}
if (!ExprResolveString(value, &name)) if (!ExprResolveString(value, &name))
{ {
ERROR("Group name must be a string\n"); ERROR("Group name must be a string\n");
@ -1462,19 +1431,9 @@ HandleSymbolsVar(VarDef * stmt, struct xkb_desc * xkb, SymbolsInfo * info)
ret = False; ret = False;
} }
else { else {
if ((tmp.uval < 1) || (tmp.uval > XkbNumKbdGroups)) info->groupInfo = XkbSetGroupInfo(0, XkbRedirectIntoRange,
{ tmp.uval);
ERROR ret = True;
("Out-of-range (1..%d) group for global groupsRedirect\n",
XkbNumKbdGroups);
ACTION("Ignoring illegal group %d\n", tmp.uval);
ret = False;
}
else {
info->groupInfo = XkbSetGroupInfo(0, XkbRedirectIntoRange,
tmp.uval);
ret = True;
}
} }
} }
else if ((elem.str == NULL) && (uStrCaseCmp(field.str, "allownone") == 0)) else if ((elem.str == NULL) && (uStrCaseCmp(field.str, "allownone") == 0))