From nobody Mon Feb 9 08:56:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1611069417; cv=none; d=zohomail.com; s=zohoarc; b=CFgFtVCNV3Ixw7plS4VSZsoyCUGP/TKapJlIUHLwxz0nQqkY9b54pT1XPnqrLV04+1fV4CZTYD/VtKjBfgFGCXsDbb/ee3AyNnc7Kx/5AJGyL+1y+wIy+2580sf/S+EVosT0gcDoxzx4Jvy72xXg6DxfqT/tLAe+f1wI+Qub/p4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611069417; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XzQQDvN2oOpxpLvfBkCEem0nzWZsBYK3ZsdptFa+w+4=; b=NDpzlKBi/80jrChAVUWWA4Xk0FTl39LTkW6HcBGbqsC256B0z1uDy1pvxNfyeMRwAFTh/tDOi6qMo97bhWl0xavLix44GWJhow/ih0cT1Yw1VwLn9esol+X3bI18RHXva0/qK4h+uuMszCXc2gPTjV7o3SfQ3OSPzXwz3gWQ2sw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1611069417590832.2224645884938; Tue, 19 Jan 2021 07:16:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.70483.126524 (Exim 4.92) (envelope-from ) id 1l1skJ-0004Jm-0g; Tue, 19 Jan 2021 15:16:39 +0000 Received: by outflank-mailman (output) from mailman id 70483.126524; Tue, 19 Jan 2021 15:16:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l1skI-0004Jf-TU; Tue, 19 Jan 2021 15:16:38 +0000 Received: by outflank-mailman (input) for mailman id 70483; Tue, 19 Jan 2021 15:16:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l1skH-0004JW-EF for xen-devel@lists.xenproject.org; Tue, 19 Jan 2021 15:16:37 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1eb8ccf4-b007-45e3-85a5-a54262a868fc; Tue, 19 Jan 2021 15:16:36 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A92DAB7BB; Tue, 19 Jan 2021 15:16:35 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 1eb8ccf4-b007-45e3-85a5-a54262a868fc X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1611069395; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XzQQDvN2oOpxpLvfBkCEem0nzWZsBYK3ZsdptFa+w+4=; b=RvMlnR4RAjkVMh5shIXBPI5mLQJesN+Oa7NtpuyHo8pQavCKjiL53kxy/GqSO9MgQhaw4c Y1xiNSZFOBAZtgo7m+rak3FC1tvw8hg25NWGNRg1ZzUFrLKW+iWeKpKINCnIyj7psMSp4X di72f3E3bqREdDdJQL8Ku/bBYNbtv4A= Subject: [PATCH v2 3/5] libxenguest: "standardize" LZO kernel decompression code From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini , Wei Liu References: Message-ID: <4fb01879-4b9c-e711-ecd0-39b0e4d50878@suse.com> Date: Tue, 19 Jan 2021 16:16:35 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" 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 Acked-by: Wei Liu --- 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 =3D dom->kernel_blob; unsigned char *out_buf =3D NULL; - size_t left =3D dom->kernel_size; + size_t left =3D dom->kernel_size, outsize; const char *msg; unsigned version; static const unsigned char magic[] =3D { @@ -471,7 +471,7 @@ static int xc_try_lzo1x_decode( cur +=3D ret; left -=3D ret; =20 - for ( *size =3D 0; ; ) + for ( outsize =3D 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 =3D "Error registering stream output"; - if ( xc_dom_register_external(dom, out_buf, *size) ) + if ( xc_dom_register_external(dom, out_buf, outsize) ) break; =20 + DOMPRINTF("%s: LZO decompress OK, 0x%zx -> 0x%zx", + __FUNCTION__, *size, outsize); + + *blob =3D out_buf; + *size =3D outsize; + return 0; } =20 @@ -508,15 +514,15 @@ static int xc_try_lzo1x_decode( break; =20 msg =3D "Output buffer overflow"; - if ( *size > SIZE_MAX - dst_len ) + if ( outsize > SIZE_MAX - dst_len ) break; =20 msg =3D "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; =20 msg =3D "Failed to (re)alloc memory"; - tmp_buf =3D realloc(out_buf, *size + dst_len); + tmp_buf =3D realloc(out_buf, outsize + dst_len); if ( tmp_buf =3D=3D NULL ) break; =20 @@ -524,7 +530,7 @@ static int xc_try_lzo1x_decode( out_len =3D dst_len; =20 ret =3D 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 !=3D dst_len ) break; =20 - *blob =3D out_buf; - *size +=3D out_len; + outsize +=3D out_len; cur +=3D src_len; left -=3D src_len; continue;