[Libguestfs] [PATCH 02/11] java: fix invalid memory access for FBuffer in struct lists

Pino Toscano ptoscano at redhat.com
Fri Mar 3 14:32:56 UTC 2017


When convering FBuffer fields of structs in each element of the return
list, make sure to allocate enough buffer to hold also the trailing null
character.
---
 generator/java.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/generator/java.ml b/generator/java.ml
index 8f71feb..2606f97 100644
--- a/generator/java.ml
+++ b/generator/java.ml
@@ -1038,7 +1038,7 @@ and generate_java_struct_list_return typ jtyp cols =
       | FBuffer ->
         pr "    {\n";
         pr "      size_t len = r->val[i].%s_len;\n" name;
-        pr "      CLEANUP_FREE char *s = malloc (len);\n";
+        pr "      CLEANUP_FREE char *s = malloc (len + 1);\n";
         pr "      if (s == NULL) {\n";
         pr "        throw_out_of_memory (env, \"malloc\");\n";
         pr "        goto ret_error;\n";
-- 
2.9.3




More information about the Libguestfs mailing list