Skip to content

Commit cc08596

Browse files
committed
Validate input to PIF.set_property
We currently only accept the "gro" property, which can be "on" of "off". Signed-off-by: Rob Hoes <[email protected]>
1 parent 96d8dfe commit cc08596

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ocaml/xapi/xapi_pif.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ let make_pif_metrics ~__context =
280280
~other_config:[] in
281281
metrics
282282

283+
let property_names_and_values = [
284+
"gro", ["on"; "off"]
285+
]
286+
283287
let default_properties = [
284288
"gro", "on"
285289
]
@@ -653,6 +657,14 @@ let set_primary_address_type ~__context ~self ~primary_address_type =
653657
Monitor_dbcalls.clear_cache_for_pif ~pif_name:(Db.PIF.get_device ~__context ~self)
654658

655659
let set_property ~__context ~self ~name ~value =
660+
let fail () = raise (Api_errors.Server_error
661+
(Api_errors.invalid_value, ["properties"; Printf.sprintf "%s = %s" name value]))
662+
in
663+
if not (List.mem_assoc name property_names_and_values) then
664+
fail ()
665+
else if not (List.mem value (List.assoc name property_names_and_values)) then
666+
fail ();
667+
656668
(* Remove the existing property with this name, then add the new value. *)
657669
let properties = List.filter
658670
(fun (property_name, _) -> property_name <> name)

0 commit comments

Comments
 (0)