From patchwork Thu Nov 15 17:44:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matt Weber X-Patchwork-Id: 998477 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=rockwellcollins.com Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42wpdy5hvkz9s3x for ; Fri, 16 Nov 2018 04:44:38 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 06091883B8; Thu, 15 Nov 2018 17:44:36 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Pqt3tENo9mRu; Thu, 15 Nov 2018 17:44:34 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 888C188399; Thu, 15 Nov 2018 17:44:34 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 800AB1BF2B7 for ; Thu, 15 Nov 2018 17:44:32 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 7CAC988399 for ; Thu, 15 Nov 2018 17:44:32 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xuWCuxYWy6c3 for ; Thu, 15 Nov 2018 17:44:30 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from secvs02.rockwellcollins.com (secvs02.rockwellcollins.com [205.175.225.241]) by whitealder.osuosl.org (Postfix) with ESMTPS id 8A77388391 for ; Thu, 15 Nov 2018 17:44:30 +0000 (UTC) Received: from ofwgwc03.rockwellcollins.com (HELO crulimr02.rockwellcollins.com) ([205.175.225.12]) by secvs02.rockwellcollins.com with ESMTP; 15 Nov 2018 11:44:29 -0600 X-Received: from largo.rockwellcollins.com (unknown [192.168.140.76]) by crulimr02.rockwellcollins.com (Postfix) with ESMTP id 09A0260257; Thu, 15 Nov 2018 11:44:29 -0600 (CST) From: Matt Weber To: buildroot@buildroot.org Date: Thu, 15 Nov 2018 11:44:26 -0600 Message-Id: <1542303868-39761-1-git-send-email-matthew.weber@rockwellcollins.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Subject: [Buildroot] [PATCH 1/3] package/xen: tools/libxc fix strncpy size X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" gcc-8 errs on possible truncation of trailing '\0' Resolves: http://autobuild.buildroot.net/results/6e0d8e962e861a32f5bf2e5031ef51c25768f1f6/ Upstream Commit: https://xenbits.xen.org/gitweb/?p=xen.git;a=commit;h=fa7789ef18bd2e716997937af71b2e4b5b00a159 Signed-off-by: Matthew Weber --- .../xen/0003-tools-libxc-fix-strncpy-size.patch | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 package/xen/0003-tools-libxc-fix-strncpy-size.patch diff --git a/package/xen/0003-tools-libxc-fix-strncpy-size.patch b/package/xen/0003-tools-libxc-fix-strncpy-size.patch new file mode 100644 index 0000000..19f4711 --- /dev/null +++ b/package/xen/0003-tools-libxc-fix-strncpy-size.patch @@ -0,0 +1,47 @@ +From fa7789ef18bd2e716997937af71b2e4b5b00a159 Mon Sep 17 00:00:00 2001 +From: =?utf8?q?Marek=20Marczykowski-G=C3=B3recki?= + +Date: Thu, 5 Apr 2018 03:50:49 +0200 +Subject: [PATCH] tools/libxc: fix strncpy size +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf8 +Content-Transfer-Encoding: 8bit + +gcc-8 warns about possible truncation of trailing '\0'. +Final character is overridden by '\0' anyway, so don't bother to copy +it. + +This fixes compile failure: + + xc_pm.c: In function 'xc_set_cpufreq_gov': + xc_pm.c:308:5: error: 'strncpy' specified bound 16 equals destination size [-Werror=stringop-truncation] + strncpy(scaling_governor, govname, CPUFREQ_NAME_LEN); + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + cc1: all warnings being treated as errors + +Signed-off-by: Marek Marczykowski-Górecki +Acked-by: Wei Liu +Release-Acked-by: Juergen Gross + +Upstream: +https://xenbits.xen.org/gitweb/?p=xen.git;a=commit;h=fa7789ef18bd2e716997937af71b2e4b5b00a159 + +--- + tools/libxc/xc_pm.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/tools/libxc/xc_pm.c b/tools/libxc/xc_pm.c +index 67e2418e3f..6f8d548e44 100644 +--- a/tools/libxc/xc_pm.c ++++ b/tools/libxc/xc_pm.c +@@ -305,7 +305,7 @@ int xc_set_cpufreq_gov(xc_interface *xch, int cpuid, char *govname) + sysctl.cmd = XEN_SYSCTL_pm_op; + sysctl.u.pm_op.cmd = SET_CPUFREQ_GOV; + sysctl.u.pm_op.cpuid = cpuid; +- strncpy(scaling_governor, govname, CPUFREQ_NAME_LEN); ++ strncpy(scaling_governor, govname, CPUFREQ_NAME_LEN - 1); + scaling_governor[CPUFREQ_NAME_LEN - 1] = '\0'; + + return xc_sysctl(xch, &sysctl); +-- +2.11.0 From patchwork Thu Nov 15 17:44:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Weber X-Patchwork-Id: 998476 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=rockwellcollins.com Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42wpdw6LzSz9s3x for ; Fri, 16 Nov 2018 04:44:36 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 0C2438898B; Thu, 15 Nov 2018 17:44:35 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HK4VNiWdVFCL; Thu, 15 Nov 2018 17:44:33 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id CE15588937; Thu, 15 Nov 2018 17:44:33 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 2F4591BF2B7 for ; Thu, 15 Nov 2018 17:44:32 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 2C867232F2 for ; Thu, 15 Nov 2018 17:44:32 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id l2dkK7YdAuVA for ; Thu, 15 Nov 2018 17:44:30 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from da1vs01.rockwellcollins.com (da1vs01.rockwellcollins.com [205.175.227.27]) by silver.osuosl.org (Postfix) with ESMTPS id 7BAFF22D55 for ; Thu, 15 Nov 2018 17:44:30 +0000 (UTC) Received: from ofwda1n02.rockwellcollins.com (HELO crulimr02.rockwellcollins.com) ([205.175.227.14]) by da1vs01.rockwellcollins.com with ESMTP; 15 Nov 2018 11:44:29 -0600 X-Received: from largo.rockwellcollins.com (unknown [192.168.140.76]) by crulimr02.rockwellcollins.com (Postfix) with ESMTP id 861BF60159; Thu, 15 Nov 2018 11:44:29 -0600 (CST) From: Matt Weber To: buildroot@buildroot.org Date: Thu, 15 Nov 2018 11:44:27 -0600 Message-Id: <1542303868-39761-2-git-send-email-matthew.weber@rockwellcollins.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1542303868-39761-1-git-send-email-matthew.weber@rockwellcollins.com> References: <1542303868-39761-1-git-send-email-matthew.weber@rockwellcollins.com> Subject: [Buildroot] [PATCH 2/3] package/xen: libxl/arm: Fix build on arm64 X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" Add zero-padding to #defined ACPI table strings that are copied. Provides sufficient characters to satisfy the length required to fully populate the destination and prevent array-bounds warnings. Add BUILD_BUG_ON sizeof checks for compile-time length checking. Upstream: http://git.yoctoproject.org/cgit/cgit.cgi/meta-virtualization/plain/recipes-extended/xen/files/xen-4.11-arm-acpi-fix-string-lengths.patch https://lists.xenproject.org/archives/html/xen-devel/2018-11/msg01726.html Signed-off-by: Matthew Weber --- Bug found while fixing: http://autobuild.buildroot.net/results/6e0d8e962e861a32f5bf2e5031ef51c25768f1f6/ --- package/xen/0005-arm-acpi-fix-string-lengths.patch | 104 +++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 package/xen/0005-arm-acpi-fix-string-lengths.patch diff --git a/package/xen/0005-arm-acpi-fix-string-lengths.patch b/package/xen/0005-arm-acpi-fix-string-lengths.patch new file mode 100644 index 0000000..769c659 --- /dev/null +++ b/package/xen/0005-arm-acpi-fix-string-lengths.patch @@ -0,0 +1,104 @@ +From 5e1a00969afe98a713bf14d1ba1902403b60e287 Mon Sep 17 00:00:00 2001 +From: Christopher Clark +Date: Thu, 16 Aug 2018 13:04:52 -0700 +Subject: [PATCH v2] libxl/arm: Fix build on arm64 + acpi w/ gcc 8.2 +To: xen-devel@lists.xenproject.org +Cc: wei.liu2@citrix.com, + ian.jackson@eu.citrix.com, + julien.grall@arm.com, + sstabellini@kernel.org + +Upstream: +http://git.yoctoproject.org/cgit/cgit.cgi/meta-virtualization/plain/recipes-extended/xen/files/xen-4.11-arm-acpi-fix-string-lengths.patch + +[modified for Xen 4.11 to add required: #include ] + +Add zero-padding to #defined ACPI table strings that are copied. +Provides sufficient characters to satisfy the length required to +fully populate the destination and prevent array-bounds warnings. +Add BUILD_BUG_ON sizeof checks for compile-time length checking. + +Signed-off-by: Christopher Clark +Reviewed-by: Stefano Stabellini +Acked-by: Wei Liu +--- +v2: add BUILD_BUG_ON length checks, requested by Wei. + +v1: Please add this patch to the backport list for the next minor + 4.11 release. + +Prior to this: gcc 8.2 objects to memcpy past bounds: + +| libxl_arm_acpi.c: In function 'make_acpi_header': +| libxl_arm_acpi.c:208:5: error: 'memcpy' forming offset [5, 6] is out +of the bounds [0, 4] [-Werror=array-bounds] +| memcpy(h->oem_id, ACPI_OEM_ID, sizeof(h->oem_id)); +| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +| libxl_arm_acpi.c:209:5: error: 'memcpy' forming offset [5, 8] is out +of the bounds [0, 4] [-Werror=array-bounds] +| memcpy(h->oem_table_id, ACPI_OEM_TABLE_ID, +sizeof(h->oem_table_id)); +| +^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +| libxl_arm_acpi.c:211:5: error: 'memcpy' forming offset 4 is out of the +bounds [0, 3] [-Werror=array-bounds] +| memcpy(h->asl_compiler_id, ACPI_ASL_COMPILER_ID, +| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +| sizeof(h->asl_compiler_id)); +| ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +| In function 'make_acpi_rsdp.isra.4', +| inlined from 'libxl__prepare_acpi' at libxl_arm_acpi.c:389:5: +| libxl_arm_acpi.c:193:5: error: 'memcpy' forming offset [5, 6] is out +of the bounds [0, 4] [-Werror=array-bounds] +| memcpy(rsdp->oem_id, ACPI_OEM_ID, sizeof(rsdp->oem_id)); +| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + tools/libxl/libxl_arm_acpi.c | 10 +++++++--- + 1 file changed, 7 insertions(+), 3 deletions(-) + +diff --git a/tools/libxl/libxl_arm_acpi.c b/tools/libxl/libxl_arm_acpi.c +index 636f724..8924396 100644 +--- a/tools/libxl/libxl_arm_acpi.c ++++ b/tools/libxl/libxl_arm_acpi.c +@@ -29,6 +29,7 @@ typedef int64_t s64; + + #include + #include ++#include + + #ifndef BITS_PER_LONG + #ifdef _LP64 +@@ -48,9 +49,9 @@ extern const unsigned char dsdt_anycpu_arm[]; + _hidden + extern const int dsdt_anycpu_arm_len; + +-#define ACPI_OEM_ID "Xen" +-#define ACPI_OEM_TABLE_ID "ARM" +-#define ACPI_ASL_COMPILER_ID "XL" ++#define ACPI_OEM_ID "Xen\0\0" ++#define ACPI_OEM_TABLE_ID "ARM\0\0\0\0" ++#define ACPI_ASL_COMPILER_ID "XL\0" + + enum { + RSDP, +@@ -190,6 +191,7 @@ static void make_acpi_rsdp(libxl__gc *gc, struct xc_dom_image *dom, + struct acpi_table_rsdp *rsdp = (void *)dom->acpi_modules[0].data + offset; + + memcpy(rsdp->signature, "RSD PTR ", sizeof(rsdp->signature)); ++ BUILD_BUG_ON(sizeof(ACPI_OEM_ID) != sizeof(rsdp->oem_id)); + memcpy(rsdp->oem_id, ACPI_OEM_ID, sizeof(rsdp->oem_id)); + rsdp->length = acpitables[RSDP].size; + rsdp->revision = 0x02; +@@ -205,9 +207,12 @@ static void make_acpi_header(struct acpi_table_header *h, const char *sig, + memcpy(h->signature, sig, 4); + h->length = len; + h->revision = rev; ++ BUILD_BUG_ON(sizeof(ACPI_OEM_ID) != sizeof(h->oem_id)); + memcpy(h->oem_id, ACPI_OEM_ID, sizeof(h->oem_id)); ++ BUILD_BUG_ON(sizeof(ACPI_OEM_TABLE_ID) != sizeof(h->oem_table_id)); + memcpy(h->oem_table_id, ACPI_OEM_TABLE_ID, sizeof(h->oem_table_id)); + h->oem_revision = 0; ++ BUILD_BUG_ON(sizeof(ACPI_ASL_COMPILER_ID) != sizeof(h->asl_compiler_id)); + memcpy(h->asl_compiler_id, ACPI_ASL_COMPILER_ID, + sizeof(h->asl_compiler_id)); + h->asl_compiler_revision = 0; From patchwork Thu Nov 15 17:44:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matt Weber X-Patchwork-Id: 998478 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=rockwellcollins.com Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42wpf02GlMz9s3x for ; Fri, 16 Nov 2018 04:44:40 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id E64B58755D; Thu, 15 Nov 2018 17:44:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mXpPeO_Q1yEU; Thu, 15 Nov 2018 17:44:35 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id 7434987517; Thu, 15 Nov 2018 17:44:35 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 869F31C2A60 for ; Thu, 15 Nov 2018 17:44:32 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 83D4588937 for ; Thu, 15 Nov 2018 17:44:32 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kasrE6aNxYO2 for ; Thu, 15 Nov 2018 17:44:31 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from ch3vs02.rockwellcollins.com (ch3vs02.rockwellcollins.com [205.175.226.29]) by hemlock.osuosl.org (Postfix) with ESMTPS id 0AC1888930 for ; Thu, 15 Nov 2018 17:44:30 +0000 (UTC) Received: from ofwch3n02.rockwellcollins.com (HELO crulimr02.rockwellcollins.com) ([205.175.226.14]) by ch3vs02.rockwellcollins.com with ESMTP; 15 Nov 2018 11:44:29 -0600 X-Received: from largo.rockwellcollins.com (unknown [192.168.140.76]) by crulimr02.rockwellcollins.com (Postfix) with ESMTP id 1704560159; Thu, 15 Nov 2018 11:44:30 -0600 (CST) From: Matt Weber To: buildroot@buildroot.org Date: Thu, 15 Nov 2018 11:44:28 -0600 Message-Id: <1542303868-39761-3-git-send-email-matthew.weber@rockwellcollins.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1542303868-39761-1-git-send-email-matthew.weber@rockwellcollins.com> References: <1542303868-39761-1-git-send-email-matthew.weber@rockwellcollins.com> MIME-Version: 1.0 Subject: [Buildroot] [PATCH 3/3] package/xen: tools/xenpmd: fix possible truncation X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" gcc-8 complains: xenpmd.c:207:9: error: 'strncpy' specified bound 32 equals destination size [-Werror=stringop-truncation] strncpy(info->oem_info, attrib_value, 32); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Upstream: https://xenbits.xen.org/gitweb/?p=xen.git;a=commit;h=938c8f53b1f80175c6f7a1399efdb984abb0cb8b Signed-off-by: Matthew Weber --- Bug found while fixing: http://autobuild.buildroot.net/results/6e0d8e962e861a32f5bf2e5031ef51c25768f1f6/ --- package/xen/0004-tools-xenpmd-truncation.patch | 74 ++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 package/xen/0004-tools-xenpmd-truncation.patch diff --git a/package/xen/0004-tools-xenpmd-truncation.patch b/package/xen/0004-tools-xenpmd-truncation.patch new file mode 100644 index 0000000..067ca9b --- /dev/null +++ b/package/xen/0004-tools-xenpmd-truncation.patch @@ -0,0 +1,74 @@ +iFrom 938c8f53b1f80175c6f7a1399efdb984abb0cb8b Mon Sep 17 00:00:00 2001 +From: =?utf8?q?Marek=20Marczykowski-G=C3=B3recki?= + +Date: Thu, 5 Apr 2018 03:50:53 +0200 +Subject: [PATCH] tools/xenpmd: fix possible '\0' truncation +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf8 +Content-Transfer-Encoding: 8bit + +gcc-8 complains: + xenpmd.c:207:9: error: 'strncpy' specified bound 32 equals destination size [-Werror=stringop-truncation] + strncpy(info->oem_info, attrib_value, 32); + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + xenpmd.c:201:9: error: 'strncpy' specified bound 32 equals destination size [-Werror=stringop-truncation] + strncpy(info->battery_type, attrib_value, 32); + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + xenpmd.c:195:9: error: 'strncpy' specified bound 32 equals destination size [-Werror=stringop-truncation] + strncpy(info->serial_number, attrib_value, 32); + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + xenpmd.c:189:9: error: 'strncpy' specified bound 32 equals destination size [-Werror=stringop-truncation] + strncpy(info->model_number, attrib_value, 32); + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Copy 31 chars, then make sure terminating '\0' is present. Those fields +are passed to strlen and as '%s' for snprintf later. + +Signed-off-by: Marek Marczykowski-Górecki +Acked-by: Wei Liu +Release-Acked-by: Juergen Gross +--- + tools/xenpmd/xenpmd.c | 12 ++++++++---- + 1 file changed, 8 insertions(+), 4 deletions(-) + +diff --git a/tools/xenpmd/xenpmd.c b/tools/xenpmd/xenpmd.c +index 689c8fd670..56412a9a81 100644 +--- a/tools/xenpmd/xenpmd.c ++++ b/tools/xenpmd/xenpmd.c +@@ -186,25 +186,29 @@ void set_attribute_battery_info(char *attrib_name, + + if ( strstr(attrib_name, "model number") ) + { +- strncpy(info->model_number, attrib_value, 32); ++ strncpy(info->model_number, attrib_value, 31); ++ info->model_number[31] = '\0'; + return; + } + + if ( strstr(attrib_name, "serial number") ) + { +- strncpy(info->serial_number, attrib_value, 32); ++ strncpy(info->serial_number, attrib_value, 31); ++ info->serial_number[31] = '\0'; + return; + } + + if ( strstr(attrib_name, "battery type") ) + { +- strncpy(info->battery_type, attrib_value, 32); ++ strncpy(info->battery_type, attrib_value, 31); ++ info->battery_type[31] = '\0'; + return; + } + + if ( strstr(attrib_name, "OEM info") ) + { +- strncpy(info->oem_info, attrib_value, 32); ++ strncpy(info->oem_info, attrib_value, 31); ++ info->oem_info[31] = '\0'; + return; + } + +-- +2.11.0 +