All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	George Dunlap <george.dunlap@citrix.com>,
	Ian Jackson <iwj@xenproject.org>, Julien Grall <julien@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>, Wei Liu <wl@xen.org>
Subject: [PATCH v3 04/15] libxenguest: "standardize" LZO kernel decompression code
Date: Tue, 26 Jan 2021 10:49:43 +0100	[thread overview]
Message-ID: <44286280-0203-8eb9-8006-43125aeb77c7@suse.com> (raw)
In-Reply-To: <2db91183-a7de-0c43-2fef-feb3523ed19b@suse.com>

Add a DOMPRINTF() other methods have, indicating success. To facilitate
this, introduce an "outsize" local variable and update *size as well as
*blob only once done. The latter then also avoids leaving a pointer to
freed memory in dom->kernel_blob in case of a decompression error.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Wei Liu <wl@xen.org>
Release-Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
v2: New.

--- a/tools/libs/guest/xg_dom_bzimageloader.c
+++ b/tools/libs/guest/xg_dom_bzimageloader.c
@@ -409,7 +409,7 @@ static int xc_try_lzo1x_decode(
     int ret;
     const unsigned char *cur = dom->kernel_blob;
     unsigned char *out_buf = NULL;
-    size_t left = dom->kernel_size;
+    size_t left = dom->kernel_size, outsize;
     const char *msg;
     unsigned version;
     static const unsigned char magic[] = {
@@ -471,7 +471,7 @@ static int xc_try_lzo1x_decode(
     cur += ret;
     left -= ret;
 
-    for ( *size = 0; ; )
+    for ( outsize = 0; ; )
     {
         lzo_uint src_len, dst_len, out_len;
         unsigned char *tmp_buf;
@@ -484,9 +484,15 @@ static int xc_try_lzo1x_decode(
         if ( !dst_len )
         {
             msg = "Error registering stream output";
-            if ( xc_dom_register_external(dom, out_buf, *size) )
+            if ( xc_dom_register_external(dom, out_buf, outsize) )
                 break;
 
+            DOMPRINTF("%s: LZO decompress OK, 0x%zx -> 0x%zx",
+                      __FUNCTION__, *size, outsize);
+
+            *blob = out_buf;
+            *size = outsize;
+
             return 0;
         }
 
@@ -508,15 +514,15 @@ static int xc_try_lzo1x_decode(
             break;
 
         msg = "Output buffer overflow";
-        if ( *size > SIZE_MAX - dst_len )
+        if ( outsize > SIZE_MAX - dst_len )
             break;
 
         msg = "Decompressed image too large";
-        if ( xc_dom_kernel_check_size(dom, *size + dst_len) )
+        if ( xc_dom_kernel_check_size(dom, outsize + dst_len) )
             break;
 
         msg = "Failed to (re)alloc memory";
-        tmp_buf = realloc(out_buf, *size + dst_len);
+        tmp_buf = realloc(out_buf, outsize + dst_len);
         if ( tmp_buf == NULL )
             break;
 
@@ -524,7 +530,7 @@ static int xc_try_lzo1x_decode(
         out_len = dst_len;
 
         ret = lzo1x_decompress_safe(cur, src_len,
-                                    out_buf + *size, &out_len, NULL);
+                                    out_buf + outsize, &out_len, NULL);
         switch ( ret )
         {
         case LZO_E_OK:
@@ -532,8 +538,7 @@ static int xc_try_lzo1x_decode(
             if ( out_len != dst_len )
                 break;
 
-            *blob = out_buf;
-            *size += out_len;
+            outsize += out_len;
             cur += src_len;
             left -= src_len;
             continue;



  parent reply	other threads:[~2021-01-26  9:49 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-26  9:46 [PATCH v3 00/15] zstd decompression for DomU-s + fallout / consolidation Jan Beulich
2021-01-26  9:48 ` [PATCH v3 01/15] libxenguest: add get_unaligned_le32() Jan Beulich
2021-01-26 11:51   ` Ian Jackson
2021-01-26  9:49 ` [PATCH v3 02/15] libxenguest: support zstd compressed kernels Jan Beulich
2021-01-26 11:53   ` Ian Jackson
2021-01-26  9:49 ` [PATCH v3 03/15] xen/decompress: make helper symbols static Jan Beulich
2021-01-26  9:49 ` Jan Beulich [this message]
2021-01-26  9:50 ` [PATCH v3 05/15] libxenguest: drop redundant decompression declarations Jan Beulich
2021-01-26  9:50 ` [PATCH v3 06/15] libxenguest: simplify kernel decompression Jan Beulich
2021-01-26  9:50 ` [PATCH v3 01/15] gunzip: drop INIT{,DATA} and STATIC Jan Beulich
2021-01-26  9:54   ` Jan Beulich
2021-01-26 11:56   ` Ian Jackson
2021-01-26 12:49     ` Jan Beulich
2021-01-26  9:51 ` [PATCH v3 08/15] bunzip: replace INIT Jan Beulich
2021-04-15 11:50   ` Julien Grall
2021-01-26  9:51 ` [PATCH v3 09/15] unlzo: " Jan Beulich
2021-04-15 11:51   ` Julien Grall
2021-01-26  9:51 ` [PATCH v3 10/15] unlzma: " Jan Beulich
2021-04-15 11:52   ` Julien Grall
2021-01-26  9:52 ` [PATCH v3 11/15] unlz4: " Jan Beulich
2021-04-15 11:56   ` Julien Grall
2021-01-26  9:52 ` [PATCH v3 12/15] unxz: replace INIT{,DATA} and STATIC Jan Beulich
2021-04-15 11:58   ` Julien Grall
2021-04-15 14:16     ` Jan Beulich
2021-04-15 14:18       ` Julien Grall
2021-04-15 14:22         ` Jan Beulich
2021-04-15 14:24           ` Julien Grall
2021-04-15 14:28             ` Jan Beulich
2021-04-15 14:55               ` Julien Grall
2021-01-26  9:52 ` [PATCH v3 13/15] unzstd: " Jan Beulich
2021-04-15 11:59   ` Julien Grall
2021-04-15 14:21     ` Jan Beulich
2021-04-15 14:22       ` Julien Grall
2021-04-15 14:25         ` Jan Beulich
2021-04-15 14:30           ` Julien Grall
2021-04-15 14:34             ` Jan Beulich
2021-04-15 14:47               ` Julien Grall
2021-01-26  9:53 ` [PATCH v3 14/15] xen/decompress: drop STATIC and INIT Jan Beulich
2021-04-15 14:21   ` Julien Grall
2021-04-15 14:32     ` Jan Beulich
2021-04-15 14:45       ` Julien Grall
2021-01-26  9:53 ` [PATCH v3 15/15] unzstd: make helper symbols static Jan Beulich
2021-04-15 12:09   ` Julien Grall
2021-04-15 14:37     ` Jan Beulich
2021-01-26 12:05 ` [PATCH v3 00/15] zstd decompression for DomU-s + fallout / consolidation Ian Jackson
2021-01-26 13:04   ` Jan Beulich
2021-01-26 13:25     ` Ian Jackson
2021-01-26 13:50       ` Jan Beulich
2021-04-15  9:20 ` Ping: " Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44286280-0203-8eb9-8006-43125aeb77c7@suse.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=iwj@xenproject.org \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.