From nobody Fri May 3 18:05:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518187462761441.5847475900151; Fri, 9 Feb 2018 06:44:22 -0800 (PST) Received: from localhost ([::1]:58942 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ek9uU-0003Hr-Ry for importer@patchew.org; Fri, 09 Feb 2018 09:44:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58752) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ek9t6-0002W5-2S for qemu-devel@nongnu.org; Fri, 09 Feb 2018 09:42:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ek9t2-0004wp-2g for qemu-devel@nongnu.org; Fri, 09 Feb 2018 09:42:52 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56046) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ek9t1-0004w9-MR; Fri, 09 Feb 2018 09:42:48 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1ek9sz-0007XF-Dx; Fri, 09 Feb 2018 15:42:45 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1ek9sg-0002Kr-Ml; Fri, 09 Feb 2018 16:42:26 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Message-Id:Date:Subject:Cc:To:From; bh=onwYfVbEHF6FUsdohfhiZnhKKr8oFQVPrKRldu8HSL4=; b=QWxJLo+YI9WXdCtTuGGUyS68j7dI4EnJFgR4+Dtcg8s0WFZWKkNBtOdFvx7ysHa2Cqil0ZlYVRyqjmaBbcnO5SPLtzW4NLw7WsaRHD6jyLmQoiIqSoc3B+J+s/wG9IUyYJ/ZL+3/tj8nFH8Uxc87/Gg7Ro4XUxeIbMIzY30YApTnKyVT7xK4RdfdeRwHoN4+85h7lOUgzOHfVBQ5NeL367AyBVBY4hzxYqM+QFiHtqO2temPE63C8Bdw2l/ffbz76km9ZPqhlHLrH5wiJxAFsJF/luyi2PTBVLkWVpKqc2CP+I0iBnr9wHZBoL2OqO3NtXhUrccilmcps2wgv78vNw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 9 Feb 2018 16:42:22 +0200 Message-Id: <20180209144222.8937-1-berto@igalia.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH] qcow2: Use g_try_realloc() in qcow2_expand_zero_clusters() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" g_realloc() aborts the program if it fails to allocate the required amount of memory. We want to detect that scenario and return an error instead, so let's use g_try_realloc(). Signed-off-by: Alberto Garcia --- block/qcow2-cluster.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index a3fec27bf9..add6d86052 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -2071,7 +2071,15 @@ int qcow2_expand_zero_clusters(BlockDriverState *bs, int l1_sectors =3D DIV_ROUND_UP(s->snapshots[i].l1_size * sizeof(uint64_t), BDRV_SECTOR_SIZE); =20 - l1_table =3D g_realloc(l1_table, l1_sectors * BDRV_SECTOR_SIZE); + uint64_t *new_l1_table =3D + g_try_realloc(l1_table, l1_sectors * BDRV_SECTOR_SIZE); + + if (!new_l1_table) { + ret =3D -ENOMEM; + goto fail; + } + + l1_table =3D new_l1_table; =20 ret =3D bdrv_read(bs->file, s->snapshots[i].l1_table_offset / BDRV_SECTOR_SIZE, --=20 2.11.0