Skip to contentSkip to conversation

ocaml/xenctrl: Check return values from hypercalls

PATCH Applied Andrew Cooper 3 participants 3 messages Jan 27, 2015 – Jan 28, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ocaml/xenctrl: Check return values from hypercalls

rather than blindly continuing and possibly using negative values.

CC Ian Campbell <[email protected]>
CC Ian Jackson <[email protected]>
CC Wei Liu <[email protected]>
CC Dave Scott <[email protected]>

---
Found with XenServers Coverity scanning. We have the sensitivity turned up higher than Coverity Scan, which does not flag these issues.

---
 tools/ocaml/libs/xc/xenctrl_stubs.c |    9 +++++++++
 1 file changed, 9 insertions(+)
tools/ocaml/libs/xc/xenctrl_stubs.c +9 -0
index f0810eb..92d064f 100644
@@ -457,6 +457,9 @@ CAMLprim value stub_xc_vcpu_getaffinity(value xch, value domid,
 	int i, len = xc_get_max_cpus(_H(xch));
 	int retval;
 
+	if (len < 1)
+		failwith_xc(_H(xch));
+
 	c_cpumap = xc_cpumap_alloc(_H(xch));
 	if (c_cpumap == NULL)
 		failwith_xc(_H(xch));
@@ -821,6 +824,12 @@ CAMLprim value stub_xc_version_version(value xch)
 
 	caml_enter_blocking_section();
 	packed = xc_version(_H(xch), XENVER_version, NULL);
+	caml_leave_blocking_section();
+
+	if (packed < 0)
+		failwith_xc(_H(xch));
+
+	caml_enter_blocking_section();
 	retval = xc_version(_H(xch), XENVER_extraversion, &extra);
 	caml_leave_blocking_section();
 
Signature · 1 line
1.7.10.4
Acked-by on v1 1/1
#1 lore raw

Looks fine to me

Quoted 47 lines · Andrew Cooper

rather than blindly continuing and possibly using negative values.

CC Ian Campbell <[email protected]>
CC Ian Jackson <[email protected]>
CC Wei Liu <[email protected]>
CC Dave Scott <[email protected]>

---
Found with XenServers Coverity scanning. We have the sensitivity turned up higher than Coverity Scan, which does not flag these issues.
---
tools/ocaml/libs/xc/xenctrl_stubs.c | 9 +++++++++

1 file changed, 9 insertions(+)
tools/ocaml/libs/xc/xenctrl_stubs.c +9 -0
index f0810eb..92d064f 100644
@@ -457,6 +457,9 @@ CAMLprim value stub_xc_vcpu_getaffinity(value xch, value domid,
 	int i, len = xc_get_max_cpus(_H(xch));
 	int retval;
 
+	if (len < 1)
+		failwith_xc(_H(xch));
+
 	c_cpumap = xc_cpumap_alloc(_H(xch));
 	if (c_cpumap == NULL)
 		failwith_xc(_H(xch));
@@ -821,6 +824,12 @@ CAMLprim value stub_xc_version_version(value xch)
 
 	caml_enter_blocking_section();
 	packed = xc_version(_H(xch), XENVER_version, NULL);
+	caml_leave_blocking_section();
+
+	if (packed < 0)
+		failwith_xc(_H(xch));
+
+	caml_enter_blocking_section();
 	retval = xc_version(_H(xch), XENVER_extraversion, &extra);
 	caml_leave_blocking_section();
 
Signature · 1 line
1.7.10.4