Skip to content

Commit

Permalink
jobspec: check min/max as ints, not unsigned
Browse files Browse the repository at this point in the history
Problem: because min/max in resource counts are read in as unsinged,
negative values in the jobspec may still pass validation

Change the value checks for min/max to use the input values cast to
signed types to ensure negative inputs are caught
  • Loading branch information
sam-maloney committed Feb 21, 2025
1 parent b348925 commit 17a1c5d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions resource/libjobspec/jobspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ void parse_yaml_count (Resource &res, const YAML::Node &cnode)

/* Validate values of entries */
res.count.min = cnode["min"].as<unsigned> ();
if (res.count.min < 1) {
if (cnode["min"].as<long long> () < 1) {
throw parse_error (cnode["min"], "\"min\" must be greater than zero");
}
if (res.count.max < res.count.min) {
if (cnode["max"] && cnode["max"].as<long long> () < cnode["min"].as<long long> ()) {
throw parse_error (cnode["max"], "\"max\" must be greater than or equal to \"min\"");
}
switch (res.count.oper) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 9999
resources:
- type: slot
count:
min: 1
max: -1
operator: "+"
operand: 1
label: foo
with:
- type: node
count: 1
tasks:
- command: [ "app" ]
slot: foo
count:
per_slot: 1
attributes:

0 comments on commit 17a1c5d

Please sign in to comment.