From nobody Sun May 5 13:33:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1520014175069136.67827385115686; Fri, 2 Mar 2018 10:09:35 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5AA502249275A; Fri, 2 Mar 2018 10:03:22 -0800 (PST) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7D7C322492743 for ; Fri, 2 Mar 2018 10:03:20 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8997F818535A; Fri, 2 Mar 2018 18:09:29 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-125-62.rdu2.redhat.com [10.10.125.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 649D02024CA8; Fri, 2 Mar 2018 18:09:28 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Fri, 2 Mar 2018 19:09:22 +0100 Message-Id: <20180302180924.4312-2-lersek@redhat.com> In-Reply-To: <20180302180924.4312-1-lersek@redhat.com> References: <20180302180924.4312-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:09:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:09:29 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [edk2] [PATCH 1/3] BaseTools/header.makefile: add "-Wno-stringop-truncation" X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Cole Robinson , Liming Gao , Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" gcc-8 (which is part of Fedora 28) enables the new warning "-Wstringop-truncation" in "-Wall". This warning is documented in detail at ; the introduction says > Warn for calls to bounded string manipulation functions such as strncat, > strncpy, and stpncpy that may either truncate the copied string or leave > the destination unchanged. It breaks the BaseTools build with: > EfiUtilityMsgs.c: In function 'PrintMessage': > EfiUtilityMsgs.c:484:9: error: 'strncat' output may be truncated copying > between 0 and 511 bytes from a string of length 511 > [-Werror=3Dstringop-truncation] > strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > EfiUtilityMsgs.c:469:9: error: 'strncat' output may be truncated copying > between 0 and 511 bytes from a string of length 511 > [-Werror=3Dstringop-truncation] > strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > EfiUtilityMsgs.c:511:5: error: 'strncat' output may be truncated copying > between 0 and 511 bytes from a string of length 511 > [-Werror=3Dstringop-truncation] > strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The right way to fix the warning would be to implement string concat with snprintf(). However, Microsoft does not appear to support snprintf() before VS2015 , so we just have to shut up the warning. The strncat() calls flagged above are valid BTW. Cc: Ard Biesheuvel Cc: Cole Robinson Cc: Liming Gao Cc: Paolo Bonzini Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Liming Gao --- BaseTools/Source/C/Makefiles/header.makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/C/Makefiles/header.makefile b/BaseTools/Sourc= e/C/Makefiles/header.makefile index 0976973bdd7b..550f8b35bce2 100644 --- a/BaseTools/Source/C/Makefiles/header.makefile +++ b/BaseTools/Source/C/Makefiles/header.makefile @@ -71,9 +71,9 @@ INCLUDE =3D $(TOOL_INCLUDE) -I $(MAKEROOT) -I $(MAKEROOT)= /Include/Common -I $(MAKE BUILD_CPPFLAGS =3D $(INCLUDE) -O2 ifeq ($(DARWIN),Darwin) # assume clang or clang compatible flags on OS X -BUILD_CFLAGS =3D -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno= -deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -c -g +BUILD_CFLAGS =3D -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno= -deprecated-declarations -Wno-stringop-truncation -Wno-self-assign -Wno-unu= sed-result -nostdlib -c -g else -BUILD_CFLAGS =3D -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno= -deprecated-declarations -Wno-unused-result -nostdlib -c -g +BUILD_CFLAGS =3D -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno= -deprecated-declarations -Wno-stringop-truncation -Wno-unused-result -nostd= lib -c -g endif BUILD_LFLAGS =3D BUILD_CXXFLAGS =3D -Wno-unused-result --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sun May 5 13:33:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1520014177552644.7976801184466; Fri, 2 Mar 2018 10:09:37 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B7E38224E691A; Fri, 2 Mar 2018 10:03:23 -0800 (PST) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C93B822492746 for ; Fri, 2 Mar 2018 10:03:21 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EEF347B4AD; Fri, 2 Mar 2018 18:09:30 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-125-62.rdu2.redhat.com [10.10.125.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9D312024CA8; Fri, 2 Mar 2018 18:09:29 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Fri, 2 Mar 2018 19:09:23 +0100 Message-Id: <20180302180924.4312-3-lersek@redhat.com> In-Reply-To: <20180302180924.4312-1-lersek@redhat.com> References: <20180302180924.4312-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 18:09:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 02 Mar 2018 18:09:31 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [edk2] [PATCH 2/3] BaseTools/header.makefile: add "-Wno-restrict" X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Cole Robinson , Liming Gao , Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" gcc-8 (which is part of Fedora 28) enables the new warning "-Wrestrict" in "-Wall". This warning is documented in detail at ; the introduction says > Warn when an object referenced by a restrict-qualified parameter (or, in > C++, a __restrict-qualified parameter) is aliased by another argument, > or when copies between such objects overlap. It breaks the BaseTools build (in the Brotli compression library) with: > In function 'ProcessCommandsInternal', > inlined from 'ProcessCommands' at dec/decode.c:1828:10: > dec/decode.c:1781:9: error: 'memcpy' accessing between 17 and 2147483631 > bytes at offsets 16 and 16 overlaps between 17 and 2147483631 bytes at > offset 16 [-Werror=3Drestrict] > memcpy(copy_dst + 16, copy_src + 16, (size_t)(i - 16)); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > In function 'ProcessCommandsInternal', > inlined from 'SafeProcessCommands' at dec/decode.c:1833:10: > dec/decode.c:1781:9: error: 'memcpy' accessing between 17 and 2147483631 > bytes at offsets 16 and 16 overlaps between 17 and 2147483631 bytes at > offset 16 [-Werror=3Drestrict] > memcpy(copy_dst + 16, copy_src + 16, (size_t)(i - 16)); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Paolo Bonzini analyzed the Brotli source in detail, and concluded that the warning is a false positive: > This seems safe to me, because it's preceded by: > > uint8_t* copy_dst =3D &s->ringbuffer[pos]; > uint8_t* copy_src =3D &s->ringbuffer[src_start]; > int dst_end =3D pos + i; > int src_end =3D src_start + i; > if (src_end > pos && dst_end > src_start) { > /* Regions intersect. */ > goto CommandPostWrapCopy; > } > > If [src_start, src_start + i) and [pos, pos + i) don't intersect, then > neither do [src_start + 16, src_start + i) and [pos + 16, pos + i). > > The if seems okay: > > (src_start + i > pos && pos + i > src_start) > > which can be rewritten to: > > (pos < src_start + i && src_start < pos + i) > > Then the numbers are in one of these two orders: > > pos <=3D src_start < pos + i <=3D src_start + i > src_start <=3D pos < src_start + i <=3D pos + i > > These two would be allowed by the "if", but they can only happen if pos > =3D=3D src_start so they degenerate to the same two orders above: > > pos <=3D src_start < src_start + i <=3D pos + i > src_start <=3D pos < pos + i <=3D src_start + i > > So it is a false positive in GCC. Disable the warning for now. Cc: Ard Biesheuvel Cc: Cole Robinson Cc: Liming Gao Cc: Paolo Bonzini Cc: Yonghong Zhu Reported-by: Cole Robinson Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Liming Gao --- BaseTools/Source/C/Makefiles/header.makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/C/Makefiles/header.makefile b/BaseTools/Sourc= e/C/Makefiles/header.makefile index 550f8b35bce2..065a998bf5de 100644 --- a/BaseTools/Source/C/Makefiles/header.makefile +++ b/BaseTools/Source/C/Makefiles/header.makefile @@ -71,9 +71,9 @@ INCLUDE =3D $(TOOL_INCLUDE) -I $(MAKEROOT) -I $(MAKEROOT)= /Include/Common -I $(MAKE BUILD_CPPFLAGS =3D $(INCLUDE) -O2 ifeq ($(DARWIN),Darwin) # assume clang or clang compatible flags on OS X -BUILD_CFLAGS =3D -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno= -deprecated-declarations -Wno-stringop-truncation -Wno-self-assign -Wno-unu= sed-result -nostdlib -c -g +BUILD_CFLAGS =3D -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno= -deprecated-declarations -Wno-stringop-truncation -Wno-restrict -Wno-self-a= ssign -Wno-unused-result -nostdlib -c -g else -BUILD_CFLAGS =3D -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno= -deprecated-declarations -Wno-stringop-truncation -Wno-unused-result -nostd= lib -c -g +BUILD_CFLAGS =3D -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno= -deprecated-declarations -Wno-stringop-truncation -Wno-restrict -Wno-unused= -result -nostdlib -c -g endif BUILD_LFLAGS =3D BUILD_CXXFLAGS =3D -Wno-unused-result --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sun May 5 13:33:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1520014180127272.97407181630035; Fri, 2 Mar 2018 10:09:40 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 218C622546BA7; Fri, 2 Mar 2018 10:03:25 -0800 (PST) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 303ED22492744 for ; Fri, 2 Mar 2018 10:03:23 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F58D8182D17; Fri, 2 Mar 2018 18:09:32 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-125-62.rdu2.redhat.com [10.10.125.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BFD22024CA8; Fri, 2 Mar 2018 18:09:31 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Fri, 2 Mar 2018 19:09:24 +0100 Message-Id: <20180302180924.4312-4-lersek@redhat.com> In-Reply-To: <20180302180924.4312-1-lersek@redhat.com> References: <20180302180924.4312-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:09:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 02 Mar 2018 18:09:32 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [edk2] [PATCH 3/3] BaseTools/GenVtf: silence false "stringop-overflow" warning with memcpy() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Cole Robinson , Liming Gao , Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" gcc-8 (which is part of Fedora 28) enables the new warning "-Wstringop-overflow" in "-Wall". This warning is documented in detail at ; the introduction says > Warn for calls to string manipulation functions such as memcpy and > strcpy that are determined to overflow the destination buffer. It breaks the BaseTools build with: > GenVtf.c: In function 'ConvertVersionInfo': > GenVtf.c:132:7: error: 'strncpy' specified bound depends on the length > of the source argument [-Werror=3Dstringop-overflow=3D] > strncpy (TemStr + 4 - Length, Str, Length); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > GenVtf.c:130:14: note: length computed here > Length =3D strlen(Str); > ^~~~~~~~~~~ It is a false positive because, while the bound equals the length of the source argument, the destination pointer is moved back towards the beginning of the destination buffer by the same amount (and this amount is range-checked first, so we can't precede the start of the dest buffer). Replace both strncpy() calls with memcpy(). Cc: Ard Biesheuvel Cc: Cole Robinson Cc: Liming Gao Cc: Paolo Bonzini Cc: Yonghong Zhu Reported-by: Cole Robinson Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Liming Gao --- BaseTools/Source/C/GenVtf/GenVtf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/C/GenVtf/GenVtf.c b/BaseTools/Source/C/GenVtf= /GenVtf.c index 65ae08eeceb8..fc7ae02203ff 100644 --- a/BaseTools/Source/C/GenVtf/GenVtf.c +++ b/BaseTools/Source/C/GenVtf/GenVtf.c @@ -129,9 +129,9 @@ Returns: } else { Length =3D strlen(Str); if (Length < 4) { - strncpy (TemStr + 4 - Length, Str, Length); + memcpy (TemStr + 4 - Length, Str, Length); } else { - strncpy (TemStr, Str + Length - 4, 4); + memcpy (TemStr, Str + Length - 4, 4); } =20 sscanf ( --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel