libxl: ocaml: fix memory corruption when converting string and key/values lists
authorRob Hoes <rob.hoes@citrix.com>
Mon, 9 Dec 2013 15:17:29 +0000 (15:17 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 10 Dec 2013 13:34:53 +0000 (13:34 +0000)
Found by Coverty. CIDs: 1128562 1128563 1128564 1128565.

Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: David Scott <dave.scott@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/ocaml/libs/xl/xenlight_stubs.c

index 80a59864f00180ce29db839962be908fbd95c085..4ea2047b80a9fe1837cf0ba1960518c998658b42 100644 (file)
@@ -151,8 +151,8 @@ static value Val_key_value_list(libxl_key_value_list *c_val)
 
        list = Val_emptylist;
        for (i = libxl_string_list_length((libxl_string_list *) c_val) - 1; i >= 0; i -= 2) {
-               val = caml_copy_string((char *) c_val[i]);
-               key = caml_copy_string((char *) c_val[i - 1]);
+               val = caml_copy_string((*c_val)[i]);
+               key = caml_copy_string((*c_val)[i - 1]);
                kv = caml_alloc_tuple(2);
                Store_field(kv, 0, key);
                Store_field(kv, 1, val);
@@ -193,7 +193,7 @@ static value Val_string_list(libxl_string_list *c_val)
 
        list = Val_emptylist;
        for (i = libxl_string_list_length(c_val) - 1; i >= 0; i--) {
-               string = caml_copy_string((char *) c_val[i]);
+               string = caml_copy_string((*c_val)[i]);
                cons = caml_alloc(2, 0);
                Store_field(cons, 0, string);   // head
                Store_field(cons, 1, list);     // tail