From patchwork Wed Aug 19 02:00:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= X-Patchwork-Id: 11722345 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4DD7A138C for ; Wed, 19 Aug 2020 02:02:47 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2A49D2075E for ; Wed, 19 Aug 2020 02:02:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SbuyKku5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2A49D2075E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=invisiblethingslab.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k8DPQ-0005Mc-3x; Wed, 19 Aug 2020 02:01:00 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k8DPP-0005MJ-7l for xen-devel@lists.xenproject.org; Wed, 19 Aug 2020 02:00:59 +0000 X-Inumbo-ID: 365a36c7-77d1-4611-a346-5c0c309524b6 Received: from wout2-smtp.messagingengine.com (unknown [64.147.123.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 365a36c7-77d1-4611-a346-5c0c309524b6; Wed, 19 Aug 2020 02:00:52 +0000 (UTC) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id A518610EB; Tue, 18 Aug 2020 22:00:50 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Tue, 18 Aug 2020 22:00:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=84aK79 JPqz1elVkqsVWGGXq2aIi/oJggegRxoBaYicQ=; b=SbuyKku5Ij/2nmplZry8Xn i1hv2x3GXZvTFx2syQ25zG4tg/IqN6XhagBtYvWS7I9Nn+RVKXfsyjRxT7mY1TGc /iSUsBus9gK4QWfLn8QRR++B1uo6Ohjom0XnHSTF4CEq0PFvIkpmkP7pJk9+pCtx ERWGQsO9AaX3ELBHSqwbiFS4kxnUdd+XbnduE4QrfF3L1RuP+n7spGQZvutqclVN +gy9Kjg/HsRibG4F2XeRnJ9WCmq28sHZdFeB+z7GEVYOGfEi2uTJFrBVO0EAHlO4 0RezmqY93s7j7GbYtKBdy6aCq0GiL7zMjai7urbBPwEG8QvW6t0pZOTG4HEduA6Q == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedruddtjedgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffogggtohfgsehtkeertdertdejnecuhfhrohhmpeforghrvghk ucforghrtgiihihkohifshhkihdqifpkrhgvtghkihcuoehmrghrmhgrrhgvkhesihhnvh hishhisghlvghthhhinhhgshhlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpeetgeet keeukeffhfejueeludehtedtkeeuiedtgffgtdfhveefueeiiefhudehgeenucfkpheple durdeigedrudejtddrkeelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomhepmhgrrhhmrghrvghksehinhhvihhsihgslhgvthhhihhnghhslhgrsg drtghomh X-ME-Proxy: Received: from localhost.localdomain (ip5b40aa59.dynamic.kabel-deutschland.de [91.64.170.89]) by mail.messagingengine.com (Postfix) with ESMTPA id 00900328005A; Tue, 18 Aug 2020 22:00:48 -0400 (EDT) From: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xenproject.org Cc: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH 1/2] libxl: workaround gcc 10.2 maybe-uninitialized warning Date: Wed, 19 Aug 2020 04:00:35 +0200 Message-Id: <20200819020036.599065-1-marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Organization: Invisible Things Lab X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" It seems xlu_pci_parse_bdf has a state machine that is too complex for gcc to understand. The build fails with: libxlu_pci.c: In function 'xlu_pci_parse_bdf': libxlu_pci.c:32:18: error: 'func' may be used uninitialized in this function [-Werror=maybe-uninitialized] 32 | pcidev->func = func; | ~~~~~~~~~~~~~^~~~~~ libxlu_pci.c:51:29: note: 'func' was declared here 51 | unsigned dom, bus, dev, func, vslot = 0; | ^~~~ libxlu_pci.c:31:17: error: 'dev' may be used uninitialized in this function [-Werror=maybe-uninitialized] 31 | pcidev->dev = dev; | ~~~~~~~~~~~~^~~~~ libxlu_pci.c:51:24: note: 'dev' was declared here 51 | unsigned dom, bus, dev, func, vslot = 0; | ^~~ libxlu_pci.c:30:17: error: 'bus' may be used uninitialized in this function [-Werror=maybe-uninitialized] 30 | pcidev->bus = bus; | ~~~~~~~~~~~~^~~~~ libxlu_pci.c:51:19: note: 'bus' was declared here 51 | unsigned dom, bus, dev, func, vslot = 0; | ^~~ libxlu_pci.c:29:20: error: 'dom' may be used uninitialized in this function [-Werror=maybe-uninitialized] 29 | pcidev->domain = domain; | ~~~~~~~~~~~~~~~^~~~~~~~ libxlu_pci.c:51:14: note: 'dom' was declared here 51 | unsigned dom, bus, dev, func, vslot = 0; | ^~~ cc1: all warnings being treated as errors Workaround it by setting the initial value to invalid value (0xffffffff) and then assert on each value being set. This way we mute the gcc warning, while still detecting bugs in the parse code. Signed-off-by: Marek Marczykowski-Górecki Reviewed-by: Ian Jackson --- tools/libxl/libxlu_pci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/libxl/libxlu_pci.c b/tools/libxl/libxlu_pci.c index 7947687661..e2709c5f89 100644 --- a/tools/libxl/libxlu_pci.c +++ b/tools/libxl/libxlu_pci.c @@ -45,10 +45,11 @@ static int pcidev_struct_fill(libxl_device_pci *pcidev, unsigned int domain, #define STATE_TYPE 9 #define STATE_RDM_STRATEGY 10 #define STATE_RESERVE_POLICY 11 +#define INVALID 0xffffffff int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_device_pci *pcidev, const char *str) { unsigned state = STATE_DOMAIN; - unsigned dom, bus, dev, func, vslot = 0; + unsigned dom = INVALID, bus = INVALID, dev = INVALID, func = INVALID, vslot = 0; char *buf2, *tok, *ptr, *end, *optkey = NULL; if ( NULL == (buf2 = ptr = strdup(str)) ) @@ -170,6 +171,8 @@ int xlu_pci_parse_bdf(XLU_Config *cfg, libxl_device_pci *pcidev, const char *str if ( tok != ptr || state != STATE_TERMINAL ) goto parse_error; + assert(dom != INVALID && bus != INVALID && dev != INVALID && func != INVALID); + /* Just a pretty way to fill in the values */ pcidev_struct_fill(pcidev, dom, bus, dev, func, vslot << 3); From patchwork Wed Aug 19 02:00:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= X-Patchwork-Id: 11722341 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 41F0F1392 for ; Wed, 19 Aug 2020 02:02:42 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1DB192067C for ; Wed, 19 Aug 2020 02:02:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="U61ulBVA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1DB192067C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=invisiblethingslab.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k8DPK-0005MO-S0; Wed, 19 Aug 2020 02:00:54 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k8DPK-0005MJ-Bo for xen-devel@lists.xenproject.org; Wed, 19 Aug 2020 02:00:54 +0000 X-Inumbo-ID: 2921ab28-113f-4bbc-ae75-9fa55b0cdf7f Received: from wout2-smtp.messagingengine.com (unknown [64.147.123.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2921ab28-113f-4bbc-ae75-9fa55b0cdf7f; Wed, 19 Aug 2020 02:00:52 +0000 (UTC) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 16B9110BE; Tue, 18 Aug 2020 22:00:51 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Tue, 18 Aug 2020 22:00:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=Q+psKKjtAH7R+iHIoeeTOiTdy9iWAsXDZugd5Q/h6 fc=; b=U61ulBVA9wSVVplQXJCe+xvulmHPBbyRpTfQsD/JGX58iiIyost4x+0d4 MeMywC9oLijG6Vnhw2uM0FlY4hFxaoNzYmnCr3nypKN/aKNNqvk/iG12zh76Ap2X oyjUspo1u9ny5NbcupQ6cs5E6M5oijO44b8M00EJ2Wr7rxVdeAEYcxgAWhEviKsM 7fgCm/iaPnQIaf9pTuwrLCHpbLKf4bAW7bqPD8aBqThEsswPe+uNDNYXaTFhMX6C Mi4XgAzVhlJeAT+JSa4/gcMiepgYXHrz/EpBi4dP6Shwe4pqb8mMbtkdKeoQPRqR rL5c2soZWY4jPpk4j5Jgzj+2TEwDQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedruddtjedgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfgggtohfgsehtkeertdertdejnecuhfhrohhmpeforghr vghkucforghrtgiihihkohifshhkihdqifpkrhgvtghkihcuoehmrghrmhgrrhgvkhesih hnvhhishhisghlvghthhhinhhgshhlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpeek jefhkeffkeekkeffiefhhffhledtgfejleeikeevffegfeelueehueeuleeljeenucfkph epledurdeigedrudejtddrkeelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghm pehmrghilhhfrhhomhepmhgrrhhmrghrvghksehinhhvihhsihgslhgvthhhihhnghhslh grsgdrtghomh X-ME-Proxy: Received: from localhost.localdomain (ip5b40aa59.dynamic.kabel-deutschland.de [91.64.170.89]) by mail.messagingengine.com (Postfix) with ESMTPA id DA891328005E; Tue, 18 Aug 2020 22:00:49 -0400 (EDT) From: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xenproject.org Cc: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH 2/2] libxl: fix -Werror=stringop-truncation in libxl__prepare_sockaddr_un Date: Wed, 19 Aug 2020 04:00:36 +0200 Message-Id: <20200819020036.599065-2-marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200819020036.599065-1-marmarek@invisiblethingslab.com> References: <20200819020036.599065-1-marmarek@invisiblethingslab.com> MIME-Version: 1.0 Organization: Invisible Things Lab X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" In file included from /usr/include/string.h:495, from libxl_internal.h:38, from libxl_utils.c:20: In function 'strncpy', inlined from 'libxl__prepare_sockaddr_un' at libxl_utils.c:1262:5: /usr/include/bits/string_fortified.h:106:10: error: '__builtin_strncpy' specified bound 108 equals destination size [-Werror=stringop-truncation] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors Signed-off-by: Marek Marczykowski-Górecki Reviewed-by: Ian Jackson --- tools/libxl/libxl_utils.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c index f360f5e228..b039143b8a 100644 --- a/tools/libxl/libxl_utils.c +++ b/tools/libxl/libxl_utils.c @@ -1252,14 +1252,14 @@ int libxl__prepare_sockaddr_un(libxl__gc *gc, struct sockaddr_un *un, const char *path, const char *what) { - if (sizeof(un->sun_path) <= strlen(path)) { + if (sizeof(un->sun_path) - 1 <= strlen(path)) { LOG(ERROR, "UNIX socket path '%s' is too long for %s", path, what); - LOG(DEBUG, "Path must be less than %zu bytes", sizeof(un->sun_path)); + LOG(DEBUG, "Path must be less than %zu bytes", sizeof(un->sun_path) - 1); return ERROR_INVAL; } memset(un, 0, sizeof(struct sockaddr_un)); un->sun_family = AF_UNIX; - strncpy(un->sun_path, path, sizeof(un->sun_path)); + strncpy(un->sun_path, path, sizeof(un->sun_path) - 1); return 0; }