Skip to contentSkip to conversation

tools/libxenhypfs: fix reading of gzipped string

PATCH In review Juergen Gross 2 participants 2 messages Jan 18, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/libxenhypfs: fix reading of gzipped string

Reading a gzipped string value from hypfs doesn't add a 0 byte at the end. Fix that.

Fixes 86234eafb95295 ("libs: add libxenhypfs")
---
 tools/libs/hypfs/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/libs/hypfs/core.c +2 -1
index f94c5ea1e2..52b30db8d7 100644
@@ -146,12 +146,13 @@ static void *xenhypfs_inflate(void *in_data, size_t *sz)
             break;
 
         out_sz = z.next_out - workbuf;
-        content = realloc(content, *sz + out_sz);
+        content = realloc(content, *sz + out_sz + 1);
         if (!content) {
             ret = Z_MEM_ERROR;
             break;
         }
         memcpy(content + *sz, workbuf, out_sz);
+        *(char *)(content + *sz + out_sz) = 0;
     }
 
     inflateEnd(&z);
Signature · 1 line
2.26.2
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Juergen Gross

Reading a gzipped string value from hypfs doesn't add a 0 byte at the end. Fix that.

Fixes 86234eafb95295 ("libs: add libxenhypfs")
Quoted 23 lines
---
 tools/libs/hypfs/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/libs/hypfs/core.c +2 -1
index f94c5ea1e2..52b30db8d7 100644
@@ -146,12 +146,13 @@ static void *xenhypfs_inflate(void *in_data, size_t *sz)
             break;
 
         out_sz = z.next_out - workbuf;
-        content = realloc(content, *sz + out_sz);
+        content = realloc(content, *sz + out_sz + 1);
         if (!content) {
             ret = Z_MEM_ERROR;
             break;
         }
         memcpy(content + *sz, workbuf, out_sz);
+        *(char *)(content + *sz + out_sz) = 0;
     }
 
     inflateEnd(&z);