From nobody Mon May 6 15:52:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566471353; cv=none; d=zoho.com; s=zohoarc; b=hlNaJMjf2ZpnqmKT965uZQQLZoWLoYKrFKYIGkbYPWhv1o+pmGYm7abnNVZFCmtJ5Zv5wjltBP6z2HPoggDGlIC2osFOHIu1aFop36PBdvTFM9U5XSVA7iXiueWpDB+UrMFNoRr9WQD968BPkANvw4R0/g0+kh2q4QLCfljtHhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566471353; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=2/4sgM//p27frFr/uA01F2zj91XL3QmPvuTf7zgbQkA=; b=g27k3ZvZhGmDkx7kc93FkwtR7404pWW8fINaV4/Pu7nFnNcw9Zro4/HUBaTgn7vWep2QbGRRHfJwryhxaGNveX1ifKcVM6uRjQ1LrcgcWLjaxVX306ieP6+I1DWCdopcPQv0zdHbEkrOC94F8ZzzY+db/9U1vB80T214foCrNnA= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566471353926117.54837538006655; Thu, 22 Aug 2019 03:55:53 -0700 (PDT) Received: from localhost ([::1]:40596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0kky-0003Ne-Tn for importer@patchew.org; Thu, 22 Aug 2019 06:55:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44380) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0kiN-0007jM-Vg for qemu-devel@nongnu.org; Thu, 22 Aug 2019 06:53:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0kiM-00040m-9Y for qemu-devel@nongnu.org; Thu, 22 Aug 2019 06:53:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47722) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0kiM-000408-0n for qemu-devel@nongnu.org; Thu, 22 Aug 2019 06:53:10 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 55FA47FDF4 for ; Thu, 22 Aug 2019 10:53:09 +0000 (UTC) Received: from dhcp-16-132.lcy.redhat.com (unknown [10.42.16.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A6B9600CD; Thu, 22 Aug 2019 10:53:03 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Thu, 22 Aug 2019 11:53:00 +0100 Message-Id: <20190822105302.26823-2-berrange@redhat.com> In-Reply-To: <20190822105302.26823-1-berrange@redhat.com> References: <20190822105302.26823-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 22 Aug 2019 10:53:09 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/3] glib: bump min required glib library version to 2.48 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Per supported platforms doc[1], the various min glib on relevant distros is: RHEL-8: 2.56.1 RHEL-7: 2.50.3 Debian (Buster): 2.58.3 Debian (Stretch): 2.50.3 OpenBSD (Ports): 2.58.3 FreeBSD (Ports): 2.56.3 OpenSUSE Leap 15: 2.54.3 SLE12-SP2: 2.48.2 Ubuntu (Xenial): 2.48.0 macOS (Homebrew): 2.56.0 This suggests that a minimum glib of 2.48 is a reasonable target. Compared to the previous version bump in commit e7b3af81597db1a6b55f2c15d030d703c6b2c6ac Author: Daniel P. Berrang=C3=A9 Date: Fri May 4 15:34:46 2018 +0100 glib: bump min required glib library version to 2.40 This will result in us dropping support for Debian Jessie and Ubuntu 14.04. As per the commit message 14.04 was already outside our list of supported build platforms and an exception was only made because one of the build hosts used during merge testing was stuck on 14.04. Debian Jessie is justified to drop because we only aim to support at most 2 major versions of Debian at any time. This means Buster and Stretch at this time. The g_strv_contains compat code is dropped as this API is present since 2.44 The g_assert_cmpmem compat code is dropped as this API is present since 2.46 [1] https://qemu.weilnetz.de/doc/qemu-doc.html#Supported-build-platforms Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Hajnoczi Signed-off-by: Daniel P. Berrang=C3=A9 --- configure | 2 +- crypto/hmac-glib.c | 5 ----- include/glib-compat.h | 42 ++---------------------------------------- 3 files changed, 3 insertions(+), 46 deletions(-) diff --git a/configure b/configure index 0173db5d9f..3a020aefd8 100755 --- a/configure +++ b/configure @@ -3636,7 +3636,7 @@ fi ########################################## # glib support probe =20 -glib_req_ver=3D2.40 +glib_req_ver=3D2.48 glib_modules=3Dgthread-2.0 if test "$modules" =3D yes; then glib_modules=3D"$glib_modules gmodule-export-2.0" diff --git a/crypto/hmac-glib.c b/crypto/hmac-glib.c index 7df627329d..509bbc74c2 100644 --- a/crypto/hmac-glib.c +++ b/crypto/hmac-glib.c @@ -21,12 +21,7 @@ static int qcrypto_hmac_alg_map[QCRYPTO_HASH_ALG__MAX] = =3D { [QCRYPTO_HASH_ALG_MD5] =3D G_CHECKSUM_MD5, [QCRYPTO_HASH_ALG_SHA1] =3D G_CHECKSUM_SHA1, [QCRYPTO_HASH_ALG_SHA256] =3D G_CHECKSUM_SHA256, -/* Support for HMAC SHA-512 in GLib 2.42 */ -#if GLIB_CHECK_VERSION(2, 42, 0) [QCRYPTO_HASH_ALG_SHA512] =3D G_CHECKSUM_SHA512, -#else - [QCRYPTO_HASH_ALG_SHA512] =3D -1, -#endif [QCRYPTO_HASH_ALG_SHA224] =3D -1, [QCRYPTO_HASH_ALG_SHA384] =3D -1, [QCRYPTO_HASH_ALG_RIPEMD160] =3D -1, diff --git a/include/glib-compat.h b/include/glib-compat.h index 1291628e09..0b0ec76299 100644 --- a/include/glib-compat.h +++ b/include/glib-compat.h @@ -19,12 +19,12 @@ /* Ask for warnings for anything that was marked deprecated in * the defined version, or before. It is a candidate for rewrite. */ -#define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_40 +#define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_48 =20 /* Ask for warnings if code tries to use function that did not * exist in the defined version. These risk breaking builds */ -#define GLIB_VERSION_MAX_ALLOWED GLIB_VERSION_2_40 +#define GLIB_VERSION_MAX_ALLOWED GLIB_VERSION_2_48 =20 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" @@ -63,26 +63,6 @@ * without generating warnings. */ =20 -static inline gboolean g_strv_contains_qemu(const gchar *const *strv, - const gchar *str) -{ -#if GLIB_CHECK_VERSION(2, 44, 0) - return g_strv_contains(strv, str); -#else - g_return_val_if_fail(strv !=3D NULL, FALSE); - g_return_val_if_fail(str !=3D NULL, FALSE); - - for (; *strv !=3D NULL; strv++) { - if (g_str_equal(str, *strv)) { - return TRUE; - } - } - - return FALSE; -#endif -} -#define g_strv_contains(a, b) g_strv_contains_qemu(a, b) - #if defined(_WIN32) && !GLIB_CHECK_VERSION(2, 50, 0) /* * g_poll has a problem on Windows when using @@ -92,24 +72,6 @@ static inline gboolean g_strv_contains_qemu(const gchar = *const *strv, gint g_poll_fixed(GPollFD *fds, guint nfds, gint timeout); #endif =20 - -#ifndef g_assert_cmpmem -#define g_assert_cmpmem(m1, l1, m2, l2) = \ - do { = \ - gconstpointer __m1 =3D m1, __m2 =3D m2; = \ - int __l1 =3D l1, __l2 =3D l2; = \ - if (__l1 !=3D __l2) { = \ - g_assertion_message_cmpnum( = \ - G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, = \ - #l1 " (len(" #m1 ")) =3D=3D " #l2 " (len(" #m2 "))", __l1,= "=3D=3D", \ - __l2, 'i'); = \ - } else if (memcmp(__m1, __m2, __l1) !=3D 0) { = \ - g_assertion_message(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUN= C, \ - "assertion failed (" #m1 " =3D=3D " #m2 ")= "); \ - } = \ - } while (0) -#endif - #pragma GCC diagnostic pop =20 #endif --=20 2.21.0 From nobody Mon May 6 15:52:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566471281; cv=none; d=zoho.com; s=zohoarc; b=myb9I/Eqh3uE6HsU8LPl/ROSTHkg9xwJp48jDCz0Ev56VUdOe3x+zQxwoc09UqJXNGcTiOB9XVLgJNgsFPaW5zrP2FVNJL05dTV5I4KqNtxrXd3FNNxuqV19o+fWeQRDw54yNMOjoGKrophoZSrjEUBw6GiQY/gzJwPr+qut5hY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566471281; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=i1BivFjepgetAbHQ4UDakP7L2IYcxlxEFgwlicdGDGU=; b=TLKblFR7JDkkGonTv3I0R13nmHiyiIfYlenE4eXVQlUjX8eiPHXQ+hwTPSABqai8XkGOMH4oWtLoUfikSp4vB+GXk/bRmNJ97TzVthTLq0q82EHv+XrXo7Dc/1NuQFHzgKSfLFf/YtW59gZ/KRivUp+gSe2DsyoCaPf7P3UPVbE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566471281821485.59028117449816; Thu, 22 Aug 2019 03:54:41 -0700 (PDT) Received: from localhost ([::1]:40566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0kjn-0001CO-E8 for importer@patchew.org; Thu, 22 Aug 2019 06:54:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44385) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0kiO-0007kN-JD for qemu-devel@nongnu.org; Thu, 22 Aug 2019 06:53:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0kiN-00041h-ED for qemu-devel@nongnu.org; Thu, 22 Aug 2019 06:53:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33108) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0kiN-00040y-5q for qemu-devel@nongnu.org; Thu, 22 Aug 2019 06:53:11 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68EF5307D921 for ; Thu, 22 Aug 2019 10:53:10 +0000 (UTC) Received: from dhcp-16-132.lcy.redhat.com (unknown [10.42.16.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90EA5600CD; Thu, 22 Aug 2019 10:53:09 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Thu, 22 Aug 2019 11:53:01 +0100 Message-Id: <20190822105302.26823-3-berrange@redhat.com> In-Reply-To: <20190822105302.26823-1-berrange@redhat.com> References: <20190822105302.26823-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 22 Aug 2019 10:53:10 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/3] crypto: define cleanup functions for use with g_autoptr X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Allow crypto structs to be used with g_autoptr, avoiding the need to explicitly call XXX_free() functions when variables go out of scope on the stack. Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Hajnoczi Signed-off-by: Daniel P. Berrang=C3=A9 --- include/crypto/block.h | 2 ++ include/crypto/cipher.h | 2 ++ include/crypto/hmac.h | 2 ++ include/crypto/ivgen.h | 2 ++ include/crypto/tlssession.h | 2 ++ 5 files changed, 10 insertions(+) diff --git a/include/crypto/block.h b/include/crypto/block.h index fe12899831..d49d2c2da9 100644 --- a/include/crypto/block.h +++ b/include/crypto/block.h @@ -268,4 +268,6 @@ uint64_t qcrypto_block_get_sector_size(QCryptoBlock *bl= ock); */ void qcrypto_block_free(QCryptoBlock *block); =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoBlock, qcrypto_block_free) + #endif /* QCRYPTO_BLOCK_H */ diff --git a/include/crypto/cipher.h b/include/crypto/cipher.h index cac90b410c..5928e5ecc7 100644 --- a/include/crypto/cipher.h +++ b/include/crypto/cipher.h @@ -170,6 +170,8 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorith= m alg, */ void qcrypto_cipher_free(QCryptoCipher *cipher); =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoCipher, qcrypto_cipher_free) + /** * qcrypto_cipher_encrypt: * @cipher: the cipher object diff --git a/include/crypto/hmac.h b/include/crypto/hmac.h index aa3c97a2ff..ad4d778416 100644 --- a/include/crypto/hmac.h +++ b/include/crypto/hmac.h @@ -65,6 +65,8 @@ QCryptoHmac *qcrypto_hmac_new(QCryptoHashAlgorithm alg, */ void qcrypto_hmac_free(QCryptoHmac *hmac); =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoHmac, qcrypto_hmac_free) + /** * qcrypto_hmac_bytesv: * @hmac: the hmac object diff --git a/include/crypto/ivgen.h b/include/crypto/ivgen.h index 9b4a62f7bb..e41521519c 100644 --- a/include/crypto/ivgen.h +++ b/include/crypto/ivgen.h @@ -203,4 +203,6 @@ QCryptoHashAlgorithm qcrypto_ivgen_get_hash(QCryptoIVGe= n *ivgen); */ void qcrypto_ivgen_free(QCryptoIVGen *ivgen); =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoIVGen, qcrypto_ivgen_free) + #endif /* QCRYPTO_IVGEN_H */ diff --git a/include/crypto/tlssession.h b/include/crypto/tlssession.h index 816300cdcc..e01e1a9dc2 100644 --- a/include/crypto/tlssession.h +++ b/include/crypto/tlssession.h @@ -160,6 +160,8 @@ QCryptoTLSSession *qcrypto_tls_session_new(QCryptoTLSCr= eds *creds, */ void qcrypto_tls_session_free(QCryptoTLSSession *sess); =20 +G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoTLSSession, qcrypto_tls_session_free) + /** * qcrypto_tls_session_check_credentials: * @sess: the TLS session object --=20 2.21.0 From nobody Mon May 6 15:52:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566471444; cv=none; d=zoho.com; s=zohoarc; b=a7T+4lhWBiUKkd+yJgw/XdRHKk7dDEsiRc8zCooEkYCN09njF4rwYXGnzunqyRKVRDqK/tvXS04Sly8FGWU0rMcesvt3Ya4dPtpTAVKTA4Mt/vI/dfabQPHgHCTZf10rYB3gKILF6n3dGUlZDXTI21ug5qaFROAri9M7E6f/5es= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566471444; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=RTRND6mpJHQchDRWK9KIp34QkKH3sA0Y8/bK7bB/QS4=; b=UneRcQudKEiW1SJWxWavIC1/ceSO9xAYGeLXP5WLv+tDSSBZkonlFJqtgWl4b0uZ0gHMI83atu76k9VK1SQn4NK73M2bxKVFW5GDkgKID3ir8wbjtTAqIzFUZ/tjHSB4Qv1ZDHQxfmAqmBo7NALUEzIoMb5sCGgcUZOPVhWYBxE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566471444750556.8271639004935; Thu, 22 Aug 2019 03:57:24 -0700 (PDT) Received: from localhost ([::1]:40640 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0kmM-0004nG-DN for importer@patchew.org; Thu, 22 Aug 2019 06:57:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44410) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0kiQ-0007oJ-Rn for qemu-devel@nongnu.org; Thu, 22 Aug 2019 06:53:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0kiO-00042a-Ld for qemu-devel@nongnu.org; Thu, 22 Aug 2019 06:53:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45238) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0kiO-000421-CD for qemu-devel@nongnu.org; Thu, 22 Aug 2019 06:53:12 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F4EB301E12C for ; Thu, 22 Aug 2019 10:53:11 +0000 (UTC) Received: from dhcp-16-132.lcy.redhat.com (unknown [10.42.16.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4DE5600CD; Thu, 22 Aug 2019 10:53:10 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Thu, 22 Aug 2019 11:53:02 +0100 Message-Id: <20190822105302.26823-4-berrange@redhat.com> In-Reply-To: <20190822105302.26823-1-berrange@redhat.com> References: <20190822105302.26823-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 22 Aug 2019 10:53:11 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/3] crypto: use auto cleanup for many stack variables X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Simplify cleanup paths by using glib's auto cleanup macros for stack variables, allowing several goto jumps / labels to be eliminated. Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Hajnoczi Signed-off-by: Daniel P. Berrang=C3=A9 --- crypto/afsplit.c | 28 +++++----------- crypto/block-luks.c | 74 +++++++++++++------------------------------ crypto/block.c | 15 +++------ crypto/pbkdf.c | 5 +-- crypto/secret.c | 39 ++++++++++------------- crypto/tlscredsanon.c | 16 ++++------ crypto/tlscredspsk.c | 5 ++- crypto/tlscredsx509.c | 16 +++------- 8 files changed, 65 insertions(+), 133 deletions(-) diff --git a/crypto/afsplit.c b/crypto/afsplit.c index 328d68c96b..b1a5a20899 100644 --- a/crypto/afsplit.c +++ b/crypto/afsplit.c @@ -58,7 +58,7 @@ static int qcrypto_afsplit_hash(QCryptoHashAlgorithm hash, } =20 for (i =3D 0; i < hashcount; i++) { - uint8_t *out =3D NULL; + g_autofree uint8_t *out =3D NULL; size_t outlen =3D 0; uint32_t iv =3D cpu_to_be32(i); struct iovec in[] =3D { @@ -79,7 +79,6 @@ static int qcrypto_afsplit_hash(QCryptoHashAlgorithm hash, assert(outlen =3D=3D digestlen); memcpy(block + (i * digestlen), out, (i =3D=3D (hashcount - 1)) ? finallen : digestlen); - g_free(out); } =20 return 0; @@ -93,13 +92,12 @@ int qcrypto_afsplit_encode(QCryptoHashAlgorithm hash, uint8_t *out, Error **errp) { - uint8_t *block =3D g_new0(uint8_t, blocklen); + g_autofree uint8_t *block =3D g_new0(uint8_t, blocklen); size_t i; - int ret =3D -1; =20 for (i =3D 0; i < (stripes - 1); i++) { if (qcrypto_random_bytes(out + (i * blocklen), blocklen, errp) < 0= ) { - goto cleanup; + return -1; } =20 qcrypto_afsplit_xor(blocklen, @@ -108,18 +106,14 @@ int qcrypto_afsplit_encode(QCryptoHashAlgorithm hash, block); if (qcrypto_afsplit_hash(hash, blocklen, block, errp) < 0) { - goto cleanup; + return -1; } } qcrypto_afsplit_xor(blocklen, in, block, out + (i * blocklen)); - ret =3D 0; - - cleanup: - g_free(block); - return ret; + return 0; } =20 =20 @@ -130,9 +124,8 @@ int qcrypto_afsplit_decode(QCryptoHashAlgorithm hash, uint8_t *out, Error **errp) { - uint8_t *block =3D g_new0(uint8_t, blocklen); + g_autofree uint8_t *block =3D g_new0(uint8_t, blocklen); size_t i; - int ret =3D -1; =20 for (i =3D 0; i < (stripes - 1); i++) { qcrypto_afsplit_xor(blocklen, @@ -141,7 +134,7 @@ int qcrypto_afsplit_decode(QCryptoHashAlgorithm hash, block); if (qcrypto_afsplit_hash(hash, blocklen, block, errp) < 0) { - goto cleanup; + return -1; } } =20 @@ -149,10 +142,5 @@ int qcrypto_afsplit_decode(QCryptoHashAlgorithm hash, in + (i * blocklen), block, out); - - ret =3D 0; - - cleanup: - g_free(block); - return ret; + return 0; } diff --git a/crypto/block-luks.c b/crypto/block-luks.c index 409ab50f20..743949adbf 100644 --- a/crypto/block-luks.c +++ b/crypto/block-luks.c @@ -425,14 +425,13 @@ qcrypto_block_luks_load_key(QCryptoBlock *block, Error **errp) { QCryptoBlockLUKS *luks =3D block->opaque; - uint8_t *splitkey; + g_autofree uint8_t *splitkey =3D NULL; size_t splitkeylen; - uint8_t *possiblekey; - int ret =3D -1; + g_autofree uint8_t *possiblekey =3D NULL; ssize_t rv; - QCryptoCipher *cipher =3D NULL; + g_autoptr(QCryptoCipher) cipher =3D NULL; uint8_t keydigest[QCRYPTO_BLOCK_LUKS_DIGEST_LEN]; - QCryptoIVGen *ivgen =3D NULL; + g_autoptr(QCryptoIVGen) ivgen =3D NULL; size_t niv; =20 if (slot->active !=3D QCRYPTO_BLOCK_LUKS_KEY_SLOT_ENABLED) { @@ -456,7 +455,7 @@ qcrypto_block_luks_load_key(QCryptoBlock *block, slot->iterations, possiblekey, masterkeylen, errp) < 0) { - goto cleanup; + return -1; } =20 /* @@ -472,7 +471,7 @@ qcrypto_block_luks_load_key(QCryptoBlock *block, opaque, errp); if (rv < 0) { - goto cleanup; + return -1; } =20 =20 @@ -482,7 +481,7 @@ qcrypto_block_luks_load_key(QCryptoBlock *block, possiblekey, masterkeylen, errp); if (!cipher) { - goto cleanup; + return -1; } =20 niv =3D qcrypto_cipher_get_iv_len(cipheralg, @@ -493,7 +492,7 @@ qcrypto_block_luks_load_key(QCryptoBlock *block, possiblekey, masterkeylen, errp); if (!ivgen) { - goto cleanup; + return -1; } =20 =20 @@ -512,7 +511,7 @@ qcrypto_block_luks_load_key(QCryptoBlock *block, splitkey, splitkeylen, errp) < 0) { - goto cleanup; + return -1; } =20 /* @@ -525,7 +524,7 @@ qcrypto_block_luks_load_key(QCryptoBlock *block, splitkey, masterkey, errp) < 0) { - goto cleanup; + return -1; } =20 =20 @@ -544,26 +543,18 @@ qcrypto_block_luks_load_key(QCryptoBlock *block, luks->header.master_key_iterations, keydigest, G_N_ELEMENTS(keydigest), errp) < 0) { - goto cleanup; + return -1; } =20 if (memcmp(keydigest, luks->header.master_key_digest, QCRYPTO_BLOCK_LUKS_DIGEST_LEN) =3D=3D 0) { /* Success, we got the right master key */ - ret =3D 1; - goto cleanup; + return 1; } =20 /* Fail, user's password was not valid for this key slot, * tell caller to try another slot */ - ret =3D 0; - - cleanup: - qcrypto_ivgen_free(ivgen); - qcrypto_cipher_free(cipher); - g_free(splitkey); - g_free(possiblekey); - return ret; + return 0; } =20 =20 @@ -644,7 +635,7 @@ qcrypto_block_luks_open(QCryptoBlock *block, int ret =3D 0; size_t i; ssize_t rv; - uint8_t *masterkey =3D NULL; + g_autofree uint8_t *masterkey =3D NULL; size_t masterkeylen; char *ivgen_name, *ivhash_name; QCryptoCipherMode ciphermode; @@ -653,7 +644,7 @@ qcrypto_block_luks_open(QCryptoBlock *block, QCryptoCipherAlgorithm ivcipheralg; QCryptoHashAlgorithm hash; QCryptoHashAlgorithm ivhash; - char *password =3D NULL; + g_autofree char *password =3D NULL; =20 if (!(flags & QCRYPTO_BLOCK_OPEN_NO_IO)) { if (!options->u.luks.key_secret) { @@ -856,17 +847,12 @@ qcrypto_block_luks_open(QCryptoBlock *block, luks->ivgen_hash_alg =3D ivhash; luks->hash_alg =3D hash; =20 - g_free(masterkey); - g_free(password); - return 0; =20 fail: - g_free(masterkey); qcrypto_block_free_cipher(block); qcrypto_ivgen_free(block->ivgen); g_free(luks); - g_free(password); return ret; } =20 @@ -891,20 +877,20 @@ qcrypto_block_luks_create(QCryptoBlock *block, QCryptoBlockLUKS *luks; QCryptoBlockCreateOptionsLUKS luks_opts; Error *local_err =3D NULL; - uint8_t *masterkey =3D NULL; - uint8_t *slotkey =3D NULL; - uint8_t *splitkey =3D NULL; + g_autofree uint8_t *masterkey =3D NULL; + g_autofree uint8_t *slotkey =3D NULL; + g_autofree uint8_t *splitkey =3D NULL; size_t splitkeylen =3D 0; size_t i; - QCryptoCipher *cipher =3D NULL; - QCryptoIVGen *ivgen =3D NULL; - char *password; + g_autoptr(QCryptoCipher) cipher =3D NULL; + g_autoptr(QCryptoIVGen) ivgen =3D NULL; + g_autofree char *password =3D NULL; const char *cipher_alg; const char *cipher_mode; const char *ivgen_alg; const char *ivgen_hash_alg =3D NULL; const char *hash_alg; - char *cipher_mode_spec =3D NULL; + g_autofree char *cipher_mode_spec =3D NULL; QCryptoCipherAlgorithm ivcipheralg =3D 0; uint64_t iters; =20 @@ -1311,15 +1297,7 @@ qcrypto_block_luks_create(QCryptoBlock *block, luks->hash_alg =3D luks_opts.hash_alg; =20 memset(masterkey, 0, luks->header.key_bytes); - g_free(masterkey); memset(slotkey, 0, luks->header.key_bytes); - g_free(slotkey); - g_free(splitkey); - g_free(password); - g_free(cipher_mode_spec); - - qcrypto_ivgen_free(ivgen); - qcrypto_cipher_free(cipher); =20 return 0; =20 @@ -1327,17 +1305,9 @@ qcrypto_block_luks_create(QCryptoBlock *block, if (masterkey) { memset(masterkey, 0, luks->header.key_bytes); } - g_free(masterkey); if (slotkey) { memset(slotkey, 0, luks->header.key_bytes); } - g_free(slotkey); - g_free(splitkey); - g_free(password); - g_free(cipher_mode_spec); - - qcrypto_ivgen_free(ivgen); - qcrypto_cipher_free(cipher); =20 qcrypto_block_free_cipher(block); qcrypto_ivgen_free(block->ivgen); diff --git a/crypto/block.c b/crypto/block.c index ee96759f7d..325752871c 100644 --- a/crypto/block.c +++ b/crypto/block.c @@ -299,15 +299,13 @@ static int do_qcrypto_block_cipher_encdec(QCryptoCiph= er *cipher, QCryptoCipherEncDecFunc func, Error **errp) { - uint8_t *iv; + g_autofree uint8_t *iv =3D niv ? g_new0(uint8_t, niv) : NULL; int ret =3D -1; uint64_t startsector =3D offset / sectorsize; =20 assert(QEMU_IS_ALIGNED(offset, sectorsize)); assert(QEMU_IS_ALIGNED(len, sectorsize)); =20 - iv =3D niv ? g_new0(uint8_t, niv) : NULL; - while (len > 0) { size_t nbytes; if (niv) { @@ -320,19 +318,19 @@ static int do_qcrypto_block_cipher_encdec(QCryptoCiph= er *cipher, } =20 if (ret < 0) { - goto cleanup; + return -1; } =20 if (qcrypto_cipher_setiv(cipher, iv, niv, errp) < 0) { - goto cleanup; + return -1; } } =20 nbytes =3D len > sectorsize ? sectorsize : len; if (func(cipher, buf, buf, nbytes, errp) < 0) { - goto cleanup; + return -1; } =20 startsector++; @@ -340,10 +338,7 @@ static int do_qcrypto_block_cipher_encdec(QCryptoCiphe= r *cipher, len -=3D nbytes; } =20 - ret =3D 0; - cleanup: - g_free(iv); - return ret; + return 0; } =20 =20 diff --git a/crypto/pbkdf.c b/crypto/pbkdf.c index b7c7c4a59b..3775ddc6c5 100644 --- a/crypto/pbkdf.c +++ b/crypto/pbkdf.c @@ -69,12 +69,10 @@ uint64_t qcrypto_pbkdf2_count_iters(QCryptoHashAlgorith= m hash, Error **errp) { uint64_t ret =3D -1; - uint8_t *out; + g_autofree uint8_t *out =3D g_new(uint8_t, nout); uint64_t iterations =3D (1 << 15); unsigned long long delta_ms, start_ms, end_ms; =20 - out =3D g_new(uint8_t, nout); - while (1) { if (qcrypto_pbkdf2_get_thread_cpu(&start_ms, errp) < 0) { goto cleanup; @@ -108,6 +106,5 @@ uint64_t qcrypto_pbkdf2_count_iters(QCryptoHashAlgorith= m hash, =20 cleanup: memset(out, 0, nout); - g_free(out); return ret; } diff --git a/crypto/secret.c b/crypto/secret.c index a75d50ae0c..1cf0ad0ce8 100644 --- a/crypto/secret.c +++ b/crypto/secret.c @@ -72,10 +72,12 @@ static void qcrypto_secret_decrypt(QCryptoSecret *secre= t, size_t *outputlen, Error **errp) { - uint8_t *key =3D NULL, *ciphertext =3D NULL, *iv =3D NULL; + g_autofree uint8_t *key =3D NULL; + g_autofree uint8_t *ciphertext =3D NULL; + g_autofree uint8_t *iv =3D NULL; size_t keylen, ciphertextlen, ivlen; - QCryptoCipher *aes =3D NULL; - uint8_t *plaintext =3D NULL; + g_autoptr(QCryptoCipher) aes =3D NULL; + g_autofree uint8_t *plaintext =3D NULL; =20 *output =3D NULL; *outputlen =3D 0; @@ -83,27 +85,27 @@ static void qcrypto_secret_decrypt(QCryptoSecret *secre= t, if (qcrypto_secret_lookup(secret->keyid, &key, &keylen, errp) < 0) { - goto cleanup; + return; } =20 if (keylen !=3D 32) { error_setg(errp, "Key should be 32 bytes in length"); - goto cleanup; + return; } =20 if (!secret->iv) { error_setg(errp, "IV is required to decrypt secret"); - goto cleanup; + return; } =20 iv =3D qbase64_decode(secret->iv, -1, &ivlen, errp); if (!iv) { - goto cleanup; + return; } if (ivlen !=3D 16) { error_setg(errp, "IV should be 16 bytes in length not %zu", ivlen); - goto cleanup; + return; } =20 aes =3D qcrypto_cipher_new(QCRYPTO_CIPHER_ALG_AES_256, @@ -111,11 +113,11 @@ static void qcrypto_secret_decrypt(QCryptoSecret *sec= ret, key, keylen, errp); if (!aes) { - goto cleanup; + return; } =20 if (qcrypto_cipher_setiv(aes, iv, ivlen, errp) < 0) { - goto cleanup; + return; } =20 if (secret->format =3D=3D QCRYPTO_SECRET_FORMAT_BASE64) { @@ -124,7 +126,7 @@ static void qcrypto_secret_decrypt(QCryptoSecret *secre= t, &ciphertextlen, errp); if (!ciphertext) { - goto cleanup; + return; } plaintext =3D g_new0(uint8_t, ciphertextlen + 1); } else { @@ -136,8 +138,7 @@ static void qcrypto_secret_decrypt(QCryptoSecret *secre= t, plaintext, ciphertextlen, errp) < 0) { - plaintext =3D NULL; - goto cleanup; + return; } =20 if (plaintext[ciphertextlen - 1] > 16 || @@ -145,9 +146,7 @@ static void qcrypto_secret_decrypt(QCryptoSecret *secre= t, error_setg(errp, "Incorrect number of padding bytes (%d) " "found on decrypted data", (int)plaintext[ciphertextlen - 1]); - g_free(plaintext); - plaintext =3D NULL; - goto cleanup; + return; } =20 /* Even though plaintext may contain arbitrary NUL @@ -156,14 +155,8 @@ static void qcrypto_secret_decrypt(QCryptoSecret *secr= et, ciphertextlen -=3D plaintext[ciphertextlen - 1]; plaintext[ciphertextlen] =3D '\0'; =20 - *output =3D plaintext; + *output =3D g_steal_pointer(&plaintext); *outputlen =3D ciphertextlen; - - cleanup: - g_free(ciphertext); - g_free(iv); - g_free(key); - qcrypto_cipher_free(aes); } =20 =20 diff --git a/crypto/tlscredsanon.c b/crypto/tlscredsanon.c index d2adc7c131..a235f60146 100644 --- a/crypto/tlscredsanon.c +++ b/crypto/tlscredsanon.c @@ -34,9 +34,8 @@ static int qcrypto_tls_creds_anon_load(QCryptoTLSCredsAnon *creds, Error **errp) { - char *dhparams =3D NULL; + g_autofree char *dhparams =3D NULL; int ret; - int rv =3D -1; =20 trace_qcrypto_tls_creds_anon_load(creds, creds->parent_obj.dir ? creds->parent_obj.dir : ""); @@ -45,20 +44,20 @@ qcrypto_tls_creds_anon_load(QCryptoTLSCredsAnon *creds, if (qcrypto_tls_creds_get_path(&creds->parent_obj, QCRYPTO_TLS_CREDS_DH_PARAMS, false, &dhparams, errp) < 0) { - goto cleanup; + return -1; } =20 ret =3D gnutls_anon_allocate_server_credentials(&creds->data.serve= r); if (ret < 0) { error_setg(errp, "Cannot allocate credentials: %s", gnutls_strerror(ret)); - goto cleanup; + return -1; } =20 if (qcrypto_tls_creds_get_dh_params_file(&creds->parent_obj, dhpar= ams, &creds->parent_obj.dh_par= ams, errp) < 0) { - goto cleanup; + return -1; } =20 gnutls_anon_set_server_dh_params(creds->data.server, @@ -68,14 +67,11 @@ qcrypto_tls_creds_anon_load(QCryptoTLSCredsAnon *creds, if (ret < 0) { error_setg(errp, "Cannot allocate credentials: %s", gnutls_strerror(ret)); - goto cleanup; + return -1; } } =20 - rv =3D 0; - cleanup: - g_free(dhparams); - return rv; + return 0; } =20 =20 diff --git a/crypto/tlscredspsk.c b/crypto/tlscredspsk.c index 4b6cf636ce..15d12e2448 100644 --- a/crypto/tlscredspsk.c +++ b/crypto/tlscredspsk.c @@ -69,7 +69,8 @@ static int qcrypto_tls_creds_psk_load(QCryptoTLSCredsPSK *creds, Error **errp) { - char *pskfile =3D NULL, *dhparams =3D NULL; + g_autofree char *pskfile =3D NULL; + g_autofree char *dhparams =3D NULL; const char *username; int ret; int rv =3D -1; @@ -139,8 +140,6 @@ qcrypto_tls_creds_psk_load(QCryptoTLSCredsPSK *creds, rv =3D 0; cleanup: g_free(key.data); - g_free(pskfile); - g_free(dhparams); return rv; } =20 diff --git a/crypto/tlscredsx509.c b/crypto/tlscredsx509.c index 56dcef3673..01fc304e5d 100644 --- a/crypto/tlscredsx509.c +++ b/crypto/tlscredsx509.c @@ -378,7 +378,7 @@ qcrypto_tls_creds_load_cert(QCryptoTLSCredsX509 *creds, { gnutls_datum_t data; gnutls_x509_crt_t cert =3D NULL; - char *buf =3D NULL; + g_autofree char *buf =3D NULL; gsize buflen; GError *gerr; int ret =3D -1; @@ -420,7 +420,6 @@ qcrypto_tls_creds_load_cert(QCryptoTLSCredsX509 *creds, gnutls_x509_crt_deinit(cert); cert =3D NULL; } - g_free(buf); return cert; } =20 @@ -434,9 +433,8 @@ qcrypto_tls_creds_load_ca_cert_list(QCryptoTLSCredsX509= *creds, Error **errp) { gnutls_datum_t data; - char *buf =3D NULL; + g_autofree char *buf =3D NULL; gsize buflen; - int ret =3D -1; GError *gerr =3D NULL; =20 *ncerts =3D 0; @@ -446,7 +444,7 @@ qcrypto_tls_creds_load_ca_cert_list(QCryptoTLSCredsX509= *creds, error_setg(errp, "Cannot load CA cert list %s: %s", certFile, gerr->message); g_error_free(gerr); - goto cleanup; + return -1; } =20 data.data =3D (unsigned char *)buf; @@ -457,15 +455,11 @@ qcrypto_tls_creds_load_ca_cert_list(QCryptoTLSCredsX5= 09 *creds, error_setg(errp, "Unable to import CA certificate list %s", certFile); - goto cleanup; + return -1; } *ncerts =3D certMax; =20 - ret =3D 0; - - cleanup: - g_free(buf); - return ret; + return 0; } =20 =20 --=20 2.21.0