All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien@xen.org>
To: xen-devel@lists.xenproject.org
Cc: Wei Liu <wl@xen.org>, Julien Grall <jgrall@amazon.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	dfaggioli@suse.com,
	Christian Lindig <christian.lindig@citrix.com>,
	David Scott <dave@recoil.org>
Subject: [Xen-devel] [PATCH 8/8] tools/ocaml: Fix stubs build when OCaml has been compiled with -safe-string
Date: Mon, 30 Mar 2020 20:21:57 +0100	[thread overview]
Message-ID: <20200330192157.1335-9-julien@xen.org> (raw)
In-Reply-To: <20200330192157.1335-1-julien@xen.org>

From: Julien Grall <jgrall@amazon.com>

The OCaml code has been fixed to handle properly -safe-string in Xen
4.11, however the stubs part were missed.

On OCaml newer than 4.06.1, String_Val() will return a const char *
when using -safe-string leading to build failure when this is used
in place where char * is expected.

The main use in Xen code base is when a new string is allocated. The
suggested approach by the OCaml community [1] is to use the helper
caml_alloc_initialized_string() but it was introduced by OCaml 4.06.1.

The next best approach is to cast String_val() to (char *) as the helper
would have done. So use it when we need to update the new string using
memcpy().

Take the opportunity to remove the unnecessary cast of the source as
mempcy() is expecting a void *.

[1] https://github.com/ocaml/ocaml/pull/1274

Reported-by: Dario Faggioli <dfaggioli@suse.com>
Signed-off-by: Julien Grall <jgrall@amazon.com>

---

    I thought about detecting whether caml_alloc_initialized_string()
    strings exist and implement it if not. This requires a bit more
    work, so I would like to get feedback first whether this is worth
    it.
---
 tools/ocaml/libs/xb/xenbus_stubs.c  | 2 +-
 tools/ocaml/libs/xc/xenctrl_stubs.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/ocaml/libs/xb/xenbus_stubs.c b/tools/ocaml/libs/xb/xenbus_stubs.c
index 001bb03371..3065181a55 100644
--- a/tools/ocaml/libs/xb/xenbus_stubs.c
+++ b/tools/ocaml/libs/xb/xenbus_stubs.c
@@ -65,7 +65,7 @@ CAMLprim value stub_string_of_header(value tid, value rid, value ty, value len)
 	};
 
 	ret = caml_alloc_string(sizeof(struct xsd_sockmsg));
-	memcpy(String_val(ret), &xsd, sizeof(struct xsd_sockmsg));
+	memcpy((char *) String_val(ret), &xsd, sizeof(struct xsd_sockmsg));
 
 	CAMLreturn(ret);
 }
diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenctrl_stubs.c
index 0fdbeac158..94aba38a42 100644
--- a/tools/ocaml/libs/xc/xenctrl_stubs.c
+++ b/tools/ocaml/libs/xc/xenctrl_stubs.c
@@ -501,7 +501,7 @@ CAMLprim value stub_xc_vcpu_context_get(value xch, value domid,
 		failwith_xc(_H(xch));
 
 	context = caml_alloc_string(sizeof(ctxt));
-	memcpy(String_val(context), (char *) &ctxt.c, sizeof(ctxt.c));
+	memcpy((char *) String_val(context), &ctxt.c, sizeof(ctxt.c));
 
 	CAMLreturn(context);
 }
@@ -680,7 +680,7 @@ CAMLprim value stub_xc_readconsolering(value xch)
 		conring_size = size;
 
 	ring = caml_alloc_string(count);
-	memcpy(String_val(ring), str, count);
+	memcpy((char *) String_val(ring), str, count);
 	free(str);
 
 	CAMLreturn(ring);
-- 
2.17.1



  parent reply	other threads:[~2020-03-30 19:22 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-30 19:21 [Xen-devel] [PATCH 0/8] Fix build with using OCaml 4.06.1 and -safe-string Julien Grall
2020-03-30 19:21 ` [Xen-devel] [PATCH 1/8] xen/guest_access: Harden copy_to_guest_offset to prevent const dest operand Julien Grall
2020-03-31  7:26   ` Jan Beulich
2020-03-31 19:13     ` Julien Grall
2020-04-01  6:48       ` Jan Beulich
2020-04-01  8:53         ` Julien Grall
2020-04-01  9:25       ` Jan Beulich
2020-04-01 21:10         ` Julien Grall
2020-03-30 19:21 ` [Xen-devel] [PATCH 2/8] xen/public: sysctl: set_parameter.params and debug.keys should be const Julien Grall
2020-03-31  7:30   ` Jan Beulich
2020-04-01  9:53     ` Julien Grall
2020-03-30 19:21 ` [Xen-devel] [PATCH 3/8] tools/libxc: misc: Mark const the parameter 'keys' of xc_send_debug_keys() Julien Grall
2020-03-31 11:14   ` Ian Jackson
2020-03-30 19:21 ` [Xen-devel] [PATCH 4/8] tools/libxc: misc: Mark const the parameter 'params' of xc_set_parameters() Julien Grall
2020-03-31 11:14   ` Ian Jackson
2020-03-30 19:21 ` [Xen-devel] [PATCH 5/8] tools/ocaml: libxc: Check error return in stub_xc_vcpu_context_get() Julien Grall
2020-03-30 19:21 ` [Xen-devel] [PATCH 6/8] tools/ocaml: libxb: Harden stub_header_of_string() Julien Grall
2020-03-30 19:21 ` [Xen-devel] [PATCH 7/8] tools/ocaml: libxb: Avoid to use String_val() when value is bytes Julien Grall
2020-03-30 19:21 ` Julien Grall [this message]
2020-03-31 11:17 ` [PATCH 0/8] Fix build with using OCaml 4.06.1 and -safe-string Ian Jackson
2020-04-01 22:00   ` Julien Grall
2020-04-16 11:25 ` Julien Grall
2020-04-16 13:25   ` Christian Lindig
2020-04-20 12:13     ` Julien Grall

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=20200330192157.1335-9-julien@xen.org \
    --to=julien@xen.org \
    --cc=christian.lindig@citrix.com \
    --cc=dave@recoil.org \
    --cc=dfaggioli@suse.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jgrall@amazon.com \
    --cc=wl@xen.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.