From nobody Tue Feb 10 05:50:31 2026 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; 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 1500995858207202.56220157926646; Tue, 25 Jul 2017 08:17:38 -0700 (PDT) Received: from localhost ([::1]:33155 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1aY-00060g-EN for importer@patchew.org; Tue, 25 Jul 2017 11:17:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46439) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1Vw-0002AR-BQ for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:12:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da1Vv-0007Ne-AL for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:12:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57198) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da1Vr-0007MV-O3; Tue, 25 Jul 2017 11:12:43 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CF469C013C4E; Tue, 25 Jul 2017 15:12:42 +0000 (UTC) Received: from localhost (ovpn-204-250.brq.redhat.com [10.40.204.250]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E0059653A; Tue, 25 Jul 2017 15:12:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CF469C013C4E Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mreitz@redhat.com From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 25 Jul 2017 17:12:31 +0200 Message-Id: <20170725151233.26077-2-mreitz@redhat.com> In-Reply-To: <20170725151233.26077-1-mreitz@redhat.com> References: <20170725151233.26077-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 25 Jul 2017 15:12:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/3] qcow: fix memory leaks related to encryption 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: qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Daniel P. Berrange" Fix leak of the 'encryptopts' string, which was mistakenly declared const. Fix leak of QemuOpts entry which should not have been deleted from the opts array. Reported by: coverity Signed-off-by: Daniel P. Berrange Message-id: 20170714103105.5781-1-berrange@redhat.com Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- block/qcow.c | 5 +++-- block/qcow2.c | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 66827d6..c08cdc4 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -768,7 +768,7 @@ static int qcow_create(const char *filename, QemuOpts *= opts, Error **errp) Error *local_err =3D NULL; int ret; BlockBackend *qcow_blk; - const char *encryptfmt =3D NULL; + char *encryptfmt =3D NULL; QDict *options; QDict *encryptopts =3D NULL; QCryptoBlockCreateOptions *crypto_opts =3D NULL; @@ -793,7 +793,7 @@ static int qcow_create(const char *filename, QemuOpts *= opts, Error **errp) goto cleanup; } } else if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) { - encryptfmt =3D "aes"; + encryptfmt =3D g_strdup("aes"); } =20 ret =3D bdrv_create_file(filename, opts, &local_err); @@ -908,6 +908,7 @@ exit: blk_unref(qcow_blk); cleanup: QDECREF(encryptopts); + g_free(encryptfmt); qcrypto_block_free(crypto); qapi_free_QCryptoBlockCreateOptions(crypto_opts); g_free(backing_file); diff --git a/block/qcow2.c b/block/qcow2.c index 90efa44..d7c600b 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2905,7 +2905,7 @@ static int qcow2_create(const char *filename, QemuOpt= s *opts, Error **errp) int version; uint64_t refcount_bits; int refcount_order; - const char *encryptfmt =3D NULL; + char *encryptfmt =3D NULL; Error *local_err =3D NULL; int ret; =20 @@ -2916,14 +2916,14 @@ static int qcow2_create(const char *filename, QemuO= pts *opts, Error **errp) backing_fmt =3D qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT); encryptfmt =3D qemu_opt_get_del(opts, BLOCK_OPT_ENCRYPT_FORMAT); if (encryptfmt) { - if (qemu_opt_get_del(opts, BLOCK_OPT_ENCRYPT)) { + if (qemu_opt_get(opts, BLOCK_OPT_ENCRYPT)) { error_setg(errp, "Options " BLOCK_OPT_ENCRYPT " and " BLOCK_OPT_ENCRYPT_FORMAT " are mutually exclusive"); ret =3D -EINVAL; goto finish; } } else if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) { - encryptfmt =3D "aes"; + encryptfmt =3D g_strdup("aes"); } cluster_size =3D qcow2_opt_get_cluster_size_del(opts, &local_err); if (local_err) { @@ -2983,6 +2983,7 @@ static int qcow2_create(const char *filename, QemuOpt= s *opts, Error **errp) finish: g_free(backing_file); g_free(backing_fmt); + g_free(encryptfmt); g_free(buf); return ret; } --=20 2.9.4