From patchwork Wed Oct 7 13:57:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bertrand Marquis X-Patchwork-Id: 11820699 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 CF8BB6CA for ; Wed, 7 Oct 2020 13:58:02 +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 A6B472076C for ; Wed, 7 Oct 2020 13:58:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A6B472076C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.3530.10114 (Exim 4.92) (envelope-from ) id 1kQ9wU-0002F3-TU; Wed, 07 Oct 2020 13:57:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 3530.10114; Wed, 07 Oct 2020 13:57:18 +0000 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" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQ9wU-0002Ew-Pw; Wed, 07 Oct 2020 13:57:18 +0000 Received: by outflank-mailman (input) for mailman id 3530; Wed, 07 Oct 2020 13:57:17 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQ9wT-0002Ej-DI for xen-devel@lists.xenproject.org; Wed, 07 Oct 2020 13:57:17 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 023cacf1-305f-497b-b5ec-5c8e5d83e1df; Wed, 07 Oct 2020 13:57:16 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F21721063; Wed, 7 Oct 2020 06:57:15 -0700 (PDT) Received: from e109506-lin.cambridge.arm.com (e109506-lin.cambridge.arm.com [10.1.198.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4D2833F66B; Wed, 7 Oct 2020 06:57:15 -0700 (PDT) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQ9wT-0002Ej-DI for xen-devel@lists.xenproject.org; Wed, 07 Oct 2020 13:57:17 +0000 X-Inumbo-ID: 023cacf1-305f-497b-b5ec-5c8e5d83e1df Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 023cacf1-305f-497b-b5ec-5c8e5d83e1df; Wed, 07 Oct 2020 13:57:16 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F21721063; Wed, 7 Oct 2020 06:57:15 -0700 (PDT) Received: from e109506-lin.cambridge.arm.com (e109506-lin.cambridge.arm.com [10.1.198.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4D2833F66B; Wed, 7 Oct 2020 06:57:15 -0700 (PDT) From: Bertrand Marquis To: xen-devel@lists.xenproject.org Cc: jgross@suse.com, Ian Jackson , Wei Liu Subject: [PATCH v3 1/2] tools/libs/stat: use memcpy instead of strncpy in getBridge Date: Wed, 7 Oct 2020 14:57:01 +0100 Message-Id: <4ecb03b40b0da6d480e95af1da8289501a3ede0a.1602078276.git.bertrand.marquis@arm.com> X-Mailer: git-send-email 2.17.1 Use memcpy in getBridge to prevent gcc warnings about truncated strings. We know that we might truncate it, so the gcc warning here is wrong. Revert previous change changing buffer sizes as bigger buffers are not needed. Signed-off-by: Bertrand Marquis Acked-by: Wei Liu --- Changes in v3: Do a memset 0 on destination buffer and use MIN between string length and resultLen - 1. Changes in v2: Use MIN between string length of de->d_name and resultLen to copy only the minimum size required and prevent crossing to from an unallocated space. --- tools/libs/stat/xenstat_linux.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/libs/stat/xenstat_linux.c b/tools/libs/stat/xenstat_linux.c index d2ee6fda64..e0d242e1bc 100644 --- a/tools/libs/stat/xenstat_linux.c +++ b/tools/libs/stat/xenstat_linux.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "xenstat_priv.h" @@ -78,8 +79,14 @@ static void getBridge(char *excludeName, char *result, size_t resultLen) sprintf(tmp, "/sys/class/net/%s/bridge", de->d_name); if (access(tmp, F_OK) == 0) { - strncpy(result, de->d_name, resultLen); - result[resultLen - 1] = 0; + /* + * Do not use strncpy to prevent compiler warning with + * gcc >= 10.0 + * If de->d_name is longer then resultLen we truncate it + */ + memset(result, 0, resultLen); + memcpy(result, de->d_name, MIN(strnlen(de->d_name, + NAME_MAX),resultLen - 1)); } } } @@ -264,7 +271,7 @@ int xenstat_collect_networks(xenstat_node * node) { /* Helper variables for parseNetDevLine() function defined above */ int i; - char line[512] = { 0 }, iface[16] = { 0 }, devBridge[256] = { 0 }, devNoBridge[257] = { 0 }; + char line[512] = { 0 }, iface[16] = { 0 }, devBridge[16] = { 0 }, devNoBridge[17] = { 0 }; unsigned long long rxBytes, rxPackets, rxErrs, rxDrops, txBytes, txPackets, txErrs, txDrops; struct priv_data *priv = get_priv_data(node->handle); From patchwork Wed Oct 7 13:57:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bertrand Marquis X-Patchwork-Id: 11820697 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 BF857139F for ; Wed, 7 Oct 2020 13:57:59 +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 90E742076C for ; Wed, 7 Oct 2020 13:57:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 90E742076C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.3531.10121 (Exim 4.92) (envelope-from ) id 1kQ9wV-0002FU-6x; Wed, 07 Oct 2020 13:57:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 3531.10121; Wed, 07 Oct 2020 13:57:19 +0000 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" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kQ9wV-0002FK-1h; Wed, 07 Oct 2020 13:57:19 +0000 Received: by outflank-mailman (input) for mailman id 3531; Wed, 07 Oct 2020 13:57:17 +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 1kQ9wT-0002Eo-SV for xen-devel@lists.xenproject.org; Wed, 07 Oct 2020 13:57:17 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 02a3b305-dfda-4ec3-988d-e418a29ca9ed; Wed, 07 Oct 2020 13:57:17 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D3796106F; Wed, 7 Oct 2020 06:57:16 -0700 (PDT) Received: from e109506-lin.cambridge.arm.com (e109506-lin.cambridge.arm.com [10.1.198.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3005B3F66B; Wed, 7 Oct 2020 06:57:16 -0700 (PDT) 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 1kQ9wT-0002Eo-SV for xen-devel@lists.xenproject.org; Wed, 07 Oct 2020 13:57:17 +0000 X-Inumbo-ID: 02a3b305-dfda-4ec3-988d-e418a29ca9ed Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 02a3b305-dfda-4ec3-988d-e418a29ca9ed; Wed, 07 Oct 2020 13:57:17 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D3796106F; Wed, 7 Oct 2020 06:57:16 -0700 (PDT) Received: from e109506-lin.cambridge.arm.com (e109506-lin.cambridge.arm.com [10.1.198.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3005B3F66B; Wed, 7 Oct 2020 06:57:16 -0700 (PDT) From: Bertrand Marquis To: xen-devel@lists.xenproject.org Cc: jgross@suse.com, Ian Jackson , Wei Liu Subject: [PATCH v3 2/2] tool/libs/light: Fix libxenlight gcc warning Date: Wed, 7 Oct 2020 14:57:02 +0100 Message-Id: <579cfa6e71a5a1392a5ae40cef358c4e8e3a0901.1602078276.git.bertrand.marquis@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <4ecb03b40b0da6d480e95af1da8289501a3ede0a.1602078276.git.bertrand.marquis@arm.com> References: <4ecb03b40b0da6d480e95af1da8289501a3ede0a.1602078276.git.bertrand.marquis@arm.com> In-Reply-To: <4ecb03b40b0da6d480e95af1da8289501a3ede0a.1602078276.git.bertrand.marquis@arm.com> References: <4ecb03b40b0da6d480e95af1da8289501a3ede0a.1602078276.git.bertrand.marquis@arm.com> Fix gcc10 compilation warning about uninitialized variable by setting it to 0. Signed-off-by: Bertrand Marquis --- Changes in v3: Rebase --- tools/libs/light/libxl_mem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/libs/light/libxl_mem.c b/tools/libs/light/libxl_mem.c index e52a9624ea..c739d00f39 100644 --- a/tools/libs/light/libxl_mem.c +++ b/tools/libs/light/libxl_mem.c @@ -562,7 +562,7 @@ out: int libxl_get_free_memory_0x040700(libxl_ctx *ctx, uint32_t *memkb) { - uint64_t my_memkb; + uint64_t my_memkb = 0; int rc; rc = libxl_get_free_memory(ctx, &my_memkb);