[Xen-devel] [PATCH 5/8] tools/ocaml: libxc: Check error return in stub_xc_vcpu_context_get()

Julien Grall posted 8 patches 5 years, 10 months ago
[Xen-devel] [PATCH 5/8] tools/ocaml: libxc: Check error return in stub_xc_vcpu_context_get()
Posted by Julien Grall 5 years, 10 months ago
From: Julien Grall <jgrall@amazon.com>

xc_vcpu_getcontext() may fail to retrieve the vcpu context. Rather than
ignoring the return value, check it and throw an error if needed.

Signed-off-by: Julien Grall <jgrall@amazon.com>
---
 tools/ocaml/libs/xc/xenctrl_stubs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenctrl_stubs.c
index 904da45c4f..0fdbeac158 100644
--- a/tools/ocaml/libs/xc/xenctrl_stubs.c
+++ b/tools/ocaml/libs/xc/xenctrl_stubs.c
@@ -497,6 +497,8 @@ CAMLprim value stub_xc_vcpu_context_get(value xch, value domid,
 	vcpu_guest_context_any_t ctxt;
 
 	ret = xc_vcpu_getcontext(_H(xch), _D(domid), Int_val(cpu), &ctxt);
+	if ( ret < 0 )
+		failwith_xc(_H(xch));
 
 	context = caml_alloc_string(sizeof(ctxt));
 	memcpy(String_val(context), (char *) &ctxt.c, sizeof(ctxt.c));
-- 
2.17.1