[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH 1/2] make xen ocaml safe-strings compliant



On Fri, 9 Mar 2018, Christian Lindig wrote:



On 9. Mar 2018, at 22:57, Michael Young <m.a.young@xxxxxxxxxxxx> wrote:

I have had a go at fixing the patch and my revised attempt is attached. I 
suspect it could be tidied up, but it works for me.

Thank you for giving this another go. What is the key difference to the 
previous patch which compiled but lead to lock up at run time? I briefly tried 
your patch and can confirm that it compiles and looks clean except for two 
trailing spaces.

— Christian

Acked-by: Christian Lindig <christian.lindig@xxxxxxxxxx>

The problem with the old patch is illustrated by the following section from the old patch for tools/ocaml/xenstored/utils.ml
@@ -85,7 +85,7 @@ let create_unix_socket name =
 let read_file_single_integer filename =
        let fd = Unix.openfile filename [ Unix.O_RDONLY ] 0o640 in
        let buf = String.make 20 (char_of_int 0) in
-       let sz = Unix.read fd buf 0 20 in
+       let sz = Unix.read fd (Bytes.of_string buf) 0 20 in
        Unix.close fd;
        int_of_string (String.sub buf 0 sz)

where the patch makes Unix.read write to a Bytes copy of buf and buf itself is unchanged, so int_of_string sees a string of null characters rather than a string to convert into a number. The net result is that information being read by oxenstored from the hypervisor is corrupted or lost. The same basic problem also occurred in a couple of places in the old patch of tools/ocaml/libs/xb/xb.ml. My fix for this is to switch to Bytes at an earlier stage, so for example the corresponding section in the new patch becomes
@@ -84,10 +84,10 @@ let create_unix_socket name =

 let read_file_single_integer filename =
        let fd = Unix.openfile filename [ Unix.O_RDONLY ] 0o640 in
-       let buf = String.make 20 (char_of_int 0) in
+       let buf = Bytes.make 20 (char_of_int 0) in
        let sz = Unix.read fd buf 0 20 in
        Unix.close fd;
-       int_of_string (String.sub buf 0 sz)
+       int_of_string (Bytes.to_string (Bytes.sub buf 0 sz))

 let path_complete path connection_path =
        if String.get path 0 <> '/' then

        Michael Young
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.