Skip to content

Commit 4bfdf7e

Browse files
authored
xapi_vif: Guarantee the device parameter is an unsigned decimal integer (#6495)
This has been always true as xapi will call valid_device on VIF creation to make sure device is an integer, but the datamodel type of 'device' is string, without any such guarantees. Specify the guarantee in the documentation and make the check stricter (int_of_string will accept "0x9fe" as an integer, for example), making sure that the device is specifically a decimal unsigned integer. allowed_VIF_devices has already enforced the unsigned decimal integer limitation on compliant clients. This could be helpful in ensuring that the clients will always be right in sorting devices as numbers, not as strings (so that "2" follows "1" instead of the string order of "1"->"10"->"11", etc.).
2 parents 0b608d5 + 09b6256 commit 4bfdf7e

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

ocaml/idl/datamodel.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3866,7 +3866,9 @@ module VIF = struct
38663866
, "order in which VIF backends are created by xapi"
38673867
)
38683868
]
3869-
"device" "order in which VIF backends are created by xapi"
3869+
"device"
3870+
"order in which VIF backends are created by xapi. Guaranteed to \
3871+
be an unsigned decimal integer."
38703872
; field ~qualifier:StaticRO ~ty:(Ref _network)
38713873
~lifecycle:
38723874
[

ocaml/idl/schematest.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ let hash x = Digest.string x |> Digest.to_hex
33
(* BEWARE: if this changes, check that schema has been bumped accordingly in
44
ocaml/idl/datamodel_common.ml, usually schema_minor_vsn *)
55

6-
let last_known_schema_hash = "dc1ccf295f957509f7eac4a005d17965"
6+
let last_known_schema_hash = "4cd835e2557dd7b5cbda6c681730c447"
77

88
let current_schema_hash : string =
99
let open Datamodel_types in

ocaml/xapi/xapi_vif_helpers.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,11 @@ let clear_current_operations ~__context ~self =
192192

193193
(**************************************************************************************)
194194

195-
(** Check if the device string has the right form *)
195+
(** Check if the device string has the right form - it should only be an
196+
unsigned decimal integer *)
196197
let valid_device dev =
197198
try
198-
ignore (int_of_string dev) ;
199+
Scanf.sscanf dev "%u%!" ignore ;
199200
true
200201
with _ -> false
201202

0 commit comments

Comments
 (0)