[PATCH] tools/libxenhypfs: fix reading of gzipped string

Juergen Gross posted 1 patch 3 years, 2 months ago
Test gitlab-ci failed
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20210118120628.11722-1-jgross@suse.com
tools/libs/hypfs/core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] tools/libxenhypfs: fix reading of gzipped string
Posted by Juergen Gross 3 years, 2 months ago
Reading a gzipped string value from hypfs doesn't add a 0 byte at the
end. Fix that.

Fixes: 86234eafb95295 ("libs: add libxenhypfs")
Signed-off-by: Juergen Gross <jgross@suse.com>
---
 tools/libs/hypfs/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/libs/hypfs/core.c b/tools/libs/hypfs/core.c
index f94c5ea1e2..52b30db8d7 100644
--- a/tools/libs/hypfs/core.c
+++ b/tools/libs/hypfs/core.c
@@ -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);
-- 
2.26.2


Re: [PATCH] tools/libxenhypfs: fix reading of gzipped string
Posted by Andrew Cooper 3 years, 2 months ago
On 18/01/2021 12:06, Juergen Gross wrote:
> Reading a gzipped string value from hypfs doesn't add a 0 byte at the
> end. Fix that.
>
> Fixes: 86234eafb95295 ("libs: add libxenhypfs")
> Signed-off-by: Juergen Gross <jgross@suse.com>

Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>

> ---
>  tools/libs/hypfs/core.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/libs/hypfs/core.c b/tools/libs/hypfs/core.c
> index f94c5ea1e2..52b30db8d7 100644
> --- a/tools/libs/hypfs/core.c
> +++ b/tools/libs/hypfs/core.c
> @@ -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);