From: Michael Young <m.a.young@durham.ac.uk>
To: Christian Lindig <christian.lindig@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>,
John Thomson <git@johnthomson.fastmail.com.au>,
Dario Faggioli <dfaggioli@suse.com>,
Marcello Seri <marcello.seri@citrix.com>,
David Scott <dave@recoil.org>,
Xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH 1/2] make xen ocaml safe-strings compliant
Date: Sat, 10 Mar 2018 00:36:12 +0000 (GMT) [thread overview]
Message-ID: <alpine.LFD.2.21.1803092352560.3092@austen3.home> (raw)
In-Reply-To: <C2CE6FE9-8010-4936-A2C7-32C0DAAD05F9@citrix.com>
[-- Attachment #1: Type: text/plain, Size: 2108 bytes --]
On Fri, 9 Mar 2018, Christian Lindig wrote:
>
>
>> On 9. Mar 2018, at 22:57, Michael Young <m.a.young@durham.ac.uk> 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@citrix.com>
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
[-- Attachment #2: Type: text/plain, Size: 157 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-03-10 0:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-30 22:55 [PATCH 1/2] make xen ocaml safe-strings compliant Michael Young
2018-02-06 16:49 ` Wei Liu
2018-02-06 21:56 ` Michael Young
2018-02-07 10:31 ` Wei Liu
2018-02-08 17:49 ` Dario Faggioli
2018-02-08 18:03 ` Wei Liu
2018-02-08 18:24 ` Wei Liu
2018-02-09 9:20 ` Christian Lindig
2018-02-09 10:06 ` Dario Faggioli
2018-02-12 14:55 ` Wei Liu
2018-03-09 22:57 ` Michael Young
2018-03-09 23:47 ` Christian Lindig
2018-03-10 0:36 ` Michael Young [this message]
2018-03-12 11:29 ` Christian Lindig
2018-03-12 19:35 ` Michael Young
2018-03-13 9:29 ` Christian Lindig
2018-03-13 14:49 ` Wei Liu
2018-02-13 0:35 ` Michael Young
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LFD.2.21.1803092352560.3092@austen3.home \
--to=m.a.young@durham.ac.uk \
--cc=christian.lindig@citrix.com \
--cc=dave@recoil.org \
--cc=dfaggioli@suse.com \
--cc=git@johnthomson.fastmail.com.au \
--cc=marcello.seri@citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).