Skip to content

Commit

Permalink
jobspec: enforce constraints on range key values
Browse files Browse the repository at this point in the history
Problem: certain nonsensical combinations of range keys are currently
not checked for when initializing ranges

Add checks ensuring that specified min/max/operator/operand
combinations are self-consistent
  • Loading branch information
sam-maloney committed Feb 14, 2025
1 parent de93f15 commit c9c8d8b
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions resource/libjobspec/jobspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,31 @@ void parse_yaml_count (Resource &res, const YAML::Node &cnode)
if (res.count.min < 1) {
throw parse_error (cnode["min"], "\"min\" must be greater than zero");
}
if (res.count.max < 1) {
throw parse_error (cnode["max"], "\"max\" must be greater than zero");
}
if (res.count.max < res.count.min) {
throw parse_error (cnode["max"], "\"max\" must be greater than or equal to \"min\"");
}
switch (res.count.oper) {
case '+':
if (res.count.operand < 1) {
throw parse_error (cnode["operand"],
"\"operand\" must be greater than zero for addition '+'");
}
break;
case '*':
if (res.count.operand < 2) {
throw parse_error (cnode["operand"],
"\"operand\" must be greater than one for multiplication '*'");
}
break;
case '^':
if (res.count.operand < 2) {
throw parse_error (cnode["operand"],
"\"operand\" must be greater than one for exponentiation '^'");
}
if (res.count.min < 2) {
throw parse_error (cnode["min"],
"\"min\" must be greater than one for exponentiation '^'");
}
break;
default:
throw parse_error (cnode["operator"], "Invalid count operator");
Expand Down

0 comments on commit c9c8d8b

Please sign in to comment.