Skip to content

Commit 321fba4

Browse files
akshayramanijohnelse
authored andcommitted
CA-130011:Prevent xapi from filling it's buffer and running out of memory while reading from an invalid device file
Signed-off-by: Akshay <[email protected]>
1 parent 4d40bcb commit 321fba4

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

ocaml/xapi/xapi_pci.ml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,10 @@ let update_pcis ~__context ~host =
121121
List.iter (fun (self, _) -> Db.PCI.destroy ~__context ~self) obsolete
122122

123123
let get_system_display_device () =
124-
let device = "/dev/vga_arbiter" in
125124
try
126-
let line =
127-
Unixext.with_input_channel
128-
device
129-
(fun chan -> input_line chan)
130-
in
125+
let device = Unix.openfile "/dev/vga_arbiter" [Unix.O_RDONLY] 0o000 in
126+
let data = Unixext.try_read_string ~limit:1024 device in
127+
let line = List.hd (String.split ~limit:2 '\n' data) in
131128
(* Example contents of line:
132129
* count:7,PCI:0000:10:00.0,decodes=io+mem,owns=io+mem,locks=none(0:0) *)
133130
let items = String.split ',' line in

0 commit comments

Comments
 (0)