From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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 E51EE223230C8 for ; Fri, 16 Feb 2018 12:38:43 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 805B081638F0; Fri, 16 Feb 2018 20:44:36 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-126-91.rdu2.redhat.com [10.10.126.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B15021411B6; Fri, 16 Feb 2018 20:44:35 +0000 (UTC) To: Ard Biesheuvel Cc: edk2-devel-01 , Michael D Kinney , Liming Gao References: <20180215183638.18578-1-lersek@redhat.com> From: Laszlo Ersek Message-ID: Date: Fri, 16 Feb 2018 21:44:33 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 16 Feb 2018 20:44:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 16 Feb 2018 20:44:36 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: Re: [PATCH 0/4] MdePkg/BaseSafeIntLib: fix undefined behavior in INT64 Sub/Add/Mult 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: , X-List-Received-Date: Fri, 16 Feb 2018 20:38:44 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 02/16/18 12:28, Ard Biesheuvel wrote: > On 15 February 2018 at 18:36, Laszlo Ersek wrote: >> Repo: https://github.com/lersek/edk2.git >> Branch: signed_range_checks >> >> Based on the discussion starting at >> . >> >> Cc: Bret Barkelew >> Cc: Liming Gao >> Cc: Michael D Kinney >> Cc: Sean Brogan >> >> Laszlo Ersek (4): >> MdePkg/BaseSafeIntLib: fix undefined behavior in SafeInt64Sub() >> MdePkg/BaseSafeIntLib: fix undefined behavior in SafeInt64Add() >> MdePkg/BaseSafeIntLib: clean up parentheses in MIN_INT64_MAGNITUDE >> MdePkg/BaseSafeIntLib: fix undefined behavior in SafeInt64Mult() >> >> MdePkg/Library/BaseSafeIntLib/SafeIntLib.c | 110 ++++++++++++++++---- >> 1 file changed, 88 insertions(+), 22 deletions(-) >> > > Hello Laszlo, > > Thanks a lot for taking the time to fix this library. I am not a C > scholar, but I have reviewed these patches to the best of my > abilities. > > Reviewed-by: Ard Biesheuvel Great, thank you! > I take it we don't need to add -fwrapv now? That's my understanding. Before starting work on this series, I tried to investigate how far "-fwrapv" support goes back, considering edk2's toolchains. With gcc, the earliest version we target is gcc-4.3 (not due to GCC4x but to UNIXGCC, ELFGCC (presumably), and CYGGCC). "-fwrapv" is available in gcc-4.3, according to the documentation. Under CLANG38, "-fwrapv" is also available (I have clang-3.8.1 installed locally). However, I couldn't check: - any VS toolchain - CLANG35 (the online docs don't seem to list "-fwrapv" -- in fact I failed to find comprehensive docs for clang-3.5) - ICC / RVCT / XCODE5 / ... So, I thought it'd be best to make the code safe. These patches should cover the signed integer "workhorse" functions, so I don't think we need "-fwrapv" right now. I also skimmed the rest of "MdePkg/Library/BaseSafeIntLib/SafeIntLib.c", and given the time I could spend, things looked OK. Thank you! Laszlo