From patchwork Tue Dec 18 17:51:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 10736077 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5FDB06C2 for ; Tue, 18 Dec 2018 17:55:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48C1929BBE for ; Tue, 18 Dec 2018 17:55:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3CC1129BD3; Tue, 18 Dec 2018 17:55:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D0A2529BBE for ; Tue, 18 Dec 2018 17:55:42 +0000 (UTC) Received: from localhost ([::1]:55608 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZJao-0006xF-3L for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Dec 2018 12:55:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33372) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZJXc-0004w7-Jr for qemu-devel@nongnu.org; Tue, 18 Dec 2018 12:52:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gZJXb-0002jG-B4 for qemu-devel@nongnu.org; Tue, 18 Dec 2018 12:52:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39544) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gZJXP-0002MZ-Ks; Tue, 18 Dec 2018 12:52:13 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA84EC04AC54; Tue, 18 Dec 2018 17:52:09 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-92.brq.redhat.com [10.40.204.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 47398105B1E2; Tue, 18 Dec 2018 17:51:48 +0000 (UTC) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Date: Tue, 18 Dec 2018 18:51:18 +0100 Message-Id: <20181218175122.3229-2-philmd@redhat.com> In-Reply-To: <20181218175122.3229-1-philmd@redhat.com> References: <20181218175122.3229-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 18 Dec 2018 17:52:09 +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] [PATCH v3 1/5] qemu/compiler: Define QEMU_NONSTRING 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: "Michael S. Tsirkin" , Jeff Cody , Ben Pye , qemu-block@nongnu.org, Juan Quintela , David Hildenbrand , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Liu Yuan , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Thomas Huth , Stefan Weil , Howard Spoelstra , "Dr. David Alan Gilbert" , =?utf-8?q?C=C3=A9dric_Le_Go?= =?utf-8?q?ater?= , Paolo Bonzini , David Gibson , Kevin Wolf , Max Reitz , 1803872@bugs.launchpad.net, Igor Mammedov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP GCC 8 introduced the -Wstringop-truncation checker to detect truncation by the strncat and strncpy functions (closely related to -Wstringop-overflow, which detect buffer overflow by string-modifying functions declared in ). Add the QEMU_NONSTRING macro which checks if the compiler supports this attribute. From the GCC manual [*]: The nonstring variable attribute specifies that an object or member declaration with type array of char, signed char, or unsigned char, or pointer to such a type is intended to store character arrays that do not necessarily contain a terminating NUL. This is useful in detecting uses of such arrays or pointers with functions that expect NUL-terminated strings, and to avoid warnings when such an array or pointer is used as an argument to a bounded string manipulation function such as strncpy. [*] https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-nonstring-variable-attribute Suggested-by: Michael S. Tsirkin Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Eric Blake --- include/qemu/compiler.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h index 261842beae..2d8f507c73 100644 --- a/include/qemu/compiler.h +++ b/include/qemu/compiler.h @@ -151,6 +151,21 @@ # define QEMU_ERROR(X) #endif +/* + * The nonstring variable attribute specifies that an object or member + * declaration with type array of char or pointer to char is intended + * to store character arrays that do not necessarily contain a terminating + * NUL character. This is useful in detecting uses of such arrays or pointers + * with functions that expect NUL-terminated strings, and to avoid warnings + * when such an array or pointer is used as an argument to a bounded string + * manipulation function such as strncpy. + */ +#if __has_attribute(nonstring) +# define QEMU_NONSTRING __attribute__((nonstring)) +#else +# define QEMU_NONSTRING +#endif + /* Implement C11 _Generic via GCC builtins. Example: * * QEMU_GENERIC(x, (float, sinf), (long double, sinl), sin) (x) From patchwork Tue Dec 18 17:51:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 10736075 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E8A513B5 for ; Tue, 18 Dec 2018 17:54:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77AB3298A1 for ; Tue, 18 Dec 2018 17:54:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67E78299A0; Tue, 18 Dec 2018 17:54:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0B489298A1 for ; Tue, 18 Dec 2018 17:53:59 +0000 (UTC) Received: from localhost ([::1]:55606 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZJZ9-0006W8-7I for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Dec 2018 12:53:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZJXt-00059X-LA for qemu-devel@nongnu.org; Tue, 18 Dec 2018 12:52:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gZJXs-0003JB-Ix for qemu-devel@nongnu.org; Tue, 18 Dec 2018 12:52:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35950) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gZJXl-00035J-Qp; Tue, 18 Dec 2018 12:52:34 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B1D15C0587E5; Tue, 18 Dec 2018 17:52:32 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-92.brq.redhat.com [10.40.204.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 493C01059581; Tue, 18 Dec 2018 17:52:10 +0000 (UTC) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Date: Tue, 18 Dec 2018 18:51:19 +0100 Message-Id: <20181218175122.3229-3-philmd@redhat.com> In-Reply-To: <20181218175122.3229-1-philmd@redhat.com> References: <20181218175122.3229-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 18 Dec 2018 17:52:32 +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] [PATCH v3 2/5] block/sheepdog: Use QEMU_NONSTRING for non NUL-terminated arrays 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: "Michael S. Tsirkin" , Jeff Cody , Ben Pye , qemu-block@nongnu.org, Juan Quintela , David Hildenbrand , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Liu Yuan , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Thomas Huth , Stefan Weil , Howard Spoelstra , "Dr. David Alan Gilbert" , =?utf-8?q?C=C3=A9dric_Le_Go?= =?utf-8?q?ater?= , Paolo Bonzini , David Gibson , Kevin Wolf , Max Reitz , 1803872@bugs.launchpad.net, Igor Mammedov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP GCC 8 added a -Wstringop-truncation warning: The -Wstringop-truncation warning added in GCC 8.0 via r254630 for bug 81117 is specifically intended to highlight likely unintended uses of the strncpy function that truncate the terminating NUL character from the source string. This new warning leads to compilation failures: CC block/sheepdog.o qemu/block/sheepdog.c: In function 'find_vdi_name': qemu/block/sheepdog.c:1239:5: error: 'strncpy' specified bound 256 equals destination size [-Werror=stringop-truncation] strncpy(buf + SD_MAX_VDI_LEN, tag, SD_MAX_VDI_TAG_LEN); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ make: *** [qemu/rules.mak:69: block/sheepdog.o] Error 1 As described previous to the strncpy() calls, the use of strncpy() is correct here: /* This pair of strncpy calls ensures that the buffer is zero-filled, * which is desirable since we'll soon be sending those bytes, and * don't want the send_req to read uninitialized data. */ strncpy(buf, filename, SD_MAX_VDI_LEN); strncpy(buf + SD_MAX_VDI_LEN, tag, SD_MAX_VDI_TAG_LEN); Use the QEMU_NONSTRING attribute, since this array is intended to store character arrays that do not necessarily contain a terminating NUL. Suggested-by: Michael S. Tsirkin Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Eric Blake --- block/sheepdog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 0125df9d49..d4ad6b119d 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1224,7 +1224,7 @@ static int find_vdi_name(BDRVSheepdogState *s, const char *filename, SheepdogVdiReq hdr; SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr; unsigned int wlen, rlen = 0; - char buf[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN]; + QEMU_NONSTRING char buf[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN]; fd = connect_to_sdog(s, errp); if (fd < 0) { From patchwork Tue Dec 18 17:51:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 10736079 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1458F13B5 for ; Tue, 18 Dec 2018 17:56:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F330529BBE for ; Tue, 18 Dec 2018 17:56:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E613029C36; Tue, 18 Dec 2018 17:56:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 71F0029BBE for ; Tue, 18 Dec 2018 17:56:52 +0000 (UTC) Received: from localhost ([::1]:55627 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZJbv-0000CI-Ph for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Dec 2018 12:56:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33542) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZJYJ-0005sG-LM for qemu-devel@nongnu.org; Tue, 18 Dec 2018 12:53:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gZJYH-00041Y-KD for qemu-devel@nongnu.org; Tue, 18 Dec 2018 12:53:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40028) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gZJYC-0003rO-4a; Tue, 18 Dec 2018 12:53:00 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D4B0B89AC1; Tue, 18 Dec 2018 17:52:58 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-92.brq.redhat.com [10.40.204.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6C2221059581; Tue, 18 Dec 2018 17:52:32 +0000 (UTC) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Date: Tue, 18 Dec 2018 18:51:20 +0100 Message-Id: <20181218175122.3229-4-philmd@redhat.com> In-Reply-To: <20181218175122.3229-1-philmd@redhat.com> References: <20181218175122.3229-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 18 Dec 2018 17:52:59 +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] [PATCH v3 3/5] hw/acpi: Use QEMU_NONSTRING for non NUL-terminated arrays 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: "Michael S. Tsirkin" , Jeff Cody , Ben Pye , qemu-block@nongnu.org, Juan Quintela , David Hildenbrand , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Liu Yuan , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Thomas Huth , Stefan Weil , Howard Spoelstra , "Dr. David Alan Gilbert" , =?utf-8?q?C=C3=A9dric_Le_Go?= =?utf-8?q?ater?= , Paolo Bonzini , David Gibson , Kevin Wolf , Max Reitz , 1803872@bugs.launchpad.net, Igor Mammedov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP GCC 8 added a -Wstringop-truncation warning: The -Wstringop-truncation warning added in GCC 8.0 via r254630 for bug 81117 is specifically intended to highlight likely unintended uses of the strncpy function that truncate the terminating NUL character from the source string. This new warning leads to compilation failures: CC hw/acpi/core.o In function 'acpi_table_install', inlined from 'acpi_table_add' at qemu/hw/acpi/core.c:296:5: qemu/hw/acpi/core.c:184:9: error: 'strncpy' specified bound 4 equals destination size [-Werror=stringop-truncation] strncpy(ext_hdr->sig, hdrs->sig, sizeof ext_hdr->sig); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ make: *** [qemu/rules.mak:69: hw/acpi/core.o] Error 1 Use the QEMU_NONSTRING attribute, since ACPI tables don't require the strings to be NUL-terminated. Suggested-by: Michael S. Tsirkin Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Igor Mammedov --- hw/acpi/core.c | 8 ++++---- include/hw/acpi/acpi-defs.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hw/acpi/core.c b/hw/acpi/core.c index aafdc61648..f60f750c3d 100644 --- a/hw/acpi/core.c +++ b/hw/acpi/core.c @@ -35,14 +35,14 @@ struct acpi_table_header { uint16_t _length; /* our length, not actual part of the hdr */ /* allows easier parsing for fw_cfg clients */ - char sig[4]; /* ACPI signature (4 ASCII characters) */ + char sig[4] QEMU_NONSTRING; /* ACPI signature (4 ASCII characters) */ uint32_t length; /* Length of table, in bytes, including header */ uint8_t revision; /* ACPI Specification minor version # */ uint8_t checksum; /* To make sum of entire table == 0 */ - char oem_id[6]; /* OEM identification */ - char oem_table_id[8]; /* OEM table identification */ + char oem_id[6] QEMU_NONSTRING; /* OEM identification */ + char oem_table_id[8] QEMU_NONSTRING; /* OEM table identification */ uint32_t oem_revision; /* OEM revision number */ - char asl_compiler_id[4]; /* ASL compiler vendor ID */ + char asl_compiler_id[4] QEMU_NONSTRING; /* ASL compiler vendor ID */ uint32_t asl_compiler_revision; /* ASL compiler revision number */ } QEMU_PACKED; diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h index af8e023968..3bf0bec8ba 100644 --- a/include/hw/acpi/acpi-defs.h +++ b/include/hw/acpi/acpi-defs.h @@ -43,7 +43,7 @@ enum { struct AcpiRsdpDescriptor { /* Root System Descriptor Pointer */ uint64_t signature; /* ACPI signature, contains "RSD PTR " */ uint8_t checksum; /* To make sum of struct == 0 */ - uint8_t oem_id [6]; /* OEM identification */ + uint8_t oem_id [6] QEMU_NONSTRING; /* OEM identification */ uint8_t revision; /* Must be 0 for 1.0, 2 for 2.0 */ uint32_t rsdt_physical_address; /* 32-bit physical address of RSDT */ uint32_t length; /* XSDT Length in bytes including hdr */ @@ -62,10 +62,10 @@ typedef struct AcpiRsdpDescriptor AcpiRsdpDescriptor; uint32_t length; /* Length of table, in bytes, including header */ \ uint8_t revision; /* ACPI Specification minor version # */ \ uint8_t checksum; /* To make sum of entire table == 0 */ \ - uint8_t oem_id [6]; /* OEM identification */ \ - uint8_t oem_table_id [8]; /* OEM table identification */ \ + uint8_t oem_id [6] QEMU_NONSTRING; /* OEM identification */ \ + uint8_t oem_table_id [8] QEMU_NONSTRING; /* OEM table identification */ \ uint32_t oem_revision; /* OEM revision number */ \ - uint8_t asl_compiler_id [4]; /* ASL compiler vendor ID */ \ + uint8_t asl_compiler_id [4] QEMU_NONSTRING; /* ASL compiler vendor ID */ \ uint32_t asl_compiler_revision; /* ASL compiler revision number */ From patchwork Tue Dec 18 17:51:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 10736083 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 69D0D6C2 for ; Tue, 18 Dec 2018 17:59:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 489B229F72 for ; Tue, 18 Dec 2018 17:59:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 381AA2AA40; Tue, 18 Dec 2018 17:59:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D428729F72 for ; Tue, 18 Dec 2018 17:59:07 +0000 (UTC) Received: from localhost ([::1]:55639 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZJe7-00022T-8N for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Dec 2018 12:59:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZJYk-00068H-6p for qemu-devel@nongnu.org; Tue, 18 Dec 2018 12:53:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gZJYj-0004tr-9y for qemu-devel@nongnu.org; Tue, 18 Dec 2018 12:53:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52702) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gZJYe-0004fb-OC; Tue, 18 Dec 2018 12:53:28 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C7ED32D7E5; Tue, 18 Dec 2018 17:53:27 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-92.brq.redhat.com [10.40.204.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E5C9E105B1E1; Tue, 18 Dec 2018 17:52:58 +0000 (UTC) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Date: Tue, 18 Dec 2018 18:51:21 +0100 Message-Id: <20181218175122.3229-5-philmd@redhat.com> In-Reply-To: <20181218175122.3229-1-philmd@redhat.com> References: <20181218175122.3229-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 18 Dec 2018 17:53:28 +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] [PATCH v3 4/5] migration: Use QEMU_NONSTRING for non NUL-terminated arrays 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: "Michael S. Tsirkin" , Jeff Cody , Ben Pye , qemu-block@nongnu.org, Juan Quintela , David Hildenbrand , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Liu Yuan , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Thomas Huth , Stefan Weil , Howard Spoelstra , "Dr. David Alan Gilbert" , =?utf-8?q?C=C3=A9dric_Le_Go?= =?utf-8?q?ater?= , Paolo Bonzini , David Gibson , Kevin Wolf , Max Reitz , 1803872@bugs.launchpad.net, Igor Mammedov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP GCC 8 added a -Wstringop-truncation warning: The -Wstringop-truncation warning added in GCC 8.0 via r254630 for bug 81117 is specifically intended to highlight likely unintended uses of the strncpy function that truncate the terminating NUL character from the source string. This new warning leads to compilation failures: CC migration/global_state.o qemu/migration/global_state.c: In function 'global_state_store_running': qemu/migration/global_state.c:45:5: error: 'strncpy' specified bound 100 equals destination size [-Werror=stringop-truncation] strncpy((char *)global_state.runstate, state, sizeof(global_state.runstate)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ make: *** [qemu/rules.mak:69: migration/global_state.o] Error 1 Use the QEMU_NONSTRING attribute, since this array is intended to store character arrays that do not necessarily contain a terminating NUL. Suggested-by: Michael S. Tsirkin Signed-off-by: Philippe Mathieu-Daudé --- migration/global_state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migration/global_state.c b/migration/global_state.c index 8e8ab5c51e..6e19333422 100644 --- a/migration/global_state.c +++ b/migration/global_state.c @@ -21,7 +21,7 @@ typedef struct { uint32_t size; - uint8_t runstate[100]; + uint8_t runstate[100] QEMU_NONSTRING; RunState state; bool received; } GlobalState; From patchwork Tue Dec 18 17:51:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 10736081 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D161613B5 for ; Tue, 18 Dec 2018 17:57:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD7E129BBE for ; Tue, 18 Dec 2018 17:57:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B192229C36; Tue, 18 Dec 2018 17:57:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 562E929BBE for ; Tue, 18 Dec 2018 17:57:51 +0000 (UTC) Received: from localhost ([::1]:55631 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZJcs-0000xN-9F for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Dec 2018 12:57:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33931) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZJZW-0006mG-Hn for qemu-devel@nongnu.org; Tue, 18 Dec 2018 12:54:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gZJZU-0006cu-ER for qemu-devel@nongnu.org; Tue, 18 Dec 2018 12:54:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38288) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gZJZM-0006MJ-Rq; Tue, 18 Dec 2018 12:54:13 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DDE1FC0BF2AA; Tue, 18 Dec 2018 17:54:11 +0000 (UTC) Received: from x1w.redhat.com (ovpn-204-92.brq.redhat.com [10.40.204.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 693DD101963A; Tue, 18 Dec 2018 17:53:28 +0000 (UTC) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Date: Tue, 18 Dec 2018 18:51:22 +0100 Message-Id: <20181218175122.3229-6-philmd@redhat.com> In-Reply-To: <20181218175122.3229-1-philmd@redhat.com> References: <20181218175122.3229-1-philmd@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 18 Dec 2018 17:54:12 +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] [PATCH v3 5/5] migration: Use strnlen() for fixed-size string 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: "Michael S. Tsirkin" , Jeff Cody , Ben Pye , qemu-block@nongnu.org, Juan Quintela , David Hildenbrand , Markus Armbruster , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Liu Yuan , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Thomas Huth , Stefan Weil , Howard Spoelstra , "Dr. David Alan Gilbert" , =?utf-8?q?C=C3=A9dric_Le_Go?= =?utf-8?q?ater?= , Paolo Bonzini , David Gibson , Kevin Wolf , Max Reitz , 1803872@bugs.launchpad.net, Igor Mammedov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP GCC 8 introduced the -Wstringop-overflow, which detect buffer overflow by string-modifying functions declared in , such strncpy(), used in global_state_store_running(). Since the global_state.runstate does not necessarily contains a terminating NUL character, We had to use the QEMU_NONSTRING attribute. The GCC manual says about the nonstring attribute: However, when the array is declared with the attribute the call to strlen is diagnosed because when the array doesn’t contain a NUL-terminated string the call is undefined. [...] In addition, calling strnlen and strndup with such arrays is safe provided a suitable bound is specified, and not diagnosed. GCC indeed found an incorrect use of strlen(), because this array is loaded by VMSTATE_BUFFER(runstate, GlobalState) then parsed using qapi_enum_parse which does not get the buffer length. Use strnlen() which returns sizeof(s->runstate) if the array is not NUL-terminated. This fixes: CC migration/global_state.o qemu/migration/global_state.c: In function 'global_state_pre_save': qemu/migration/global_state.c:109:15: error: 'strlen' argument 1 declared attribute 'nonstring' [-Werror=stringop-overflow=] s->size = strlen((char *)s->runstate) + 1; ^~~~~~~~~~~~~~~~~~~~~~~~~~~ qemu/migration/global_state.c:24:13: note: argument 'runstate' declared here uint8_t runstate[100] QEMU_NONSTRING; ^~~~~~~~ cc1: all warnings being treated as errors make: *** [qemu/rules.mak:69: migration/global_state.o] Error 1 Signed-off-by: Philippe Mathieu-Daudé --- migration/global_state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migration/global_state.c b/migration/global_state.c index 6e19333422..c19030ef62 100644 --- a/migration/global_state.c +++ b/migration/global_state.c @@ -106,7 +106,7 @@ static int global_state_pre_save(void *opaque) GlobalState *s = opaque; trace_migrate_global_state_pre_save((char *)s->runstate); - s->size = strlen((char *)s->runstate) + 1; + s->size = strnlen((char *)s->runstate, sizeof(s->runstate)) + 1; return 0; }