From nobody Fri Oct 18 06:26:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+101830+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+101830+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1679690999; cv=none; d=zohomail.com; s=zohoarc; b=l+/HQ7/HrvCkqZuZ5ua9xq1WWqnEHoM0cwL9wyK0hegEELLckuG+lhFmTV4ynHBWNLtqjR4eK4yINx+uwb/sUS/cJC9K3Z99u3c9wWW4Ylcss61lt6OXk9MuYfrockCeg3Ih0agFoLByYG3G3rOw9pSFhxpkJL4m6D3pJTtw+9E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679690999; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=TCu7dck6FxPh6U8LuHLPT0m0h5g3/nHmFXtQSb58b78=; b=ZraRMAT0smqrLv3o+MGLcrRoAEzrWxWsSVqtDI3U8ymgn5NvJ5e4Bj9rnja0hknjfHUyAr30Auc3eVgSPOyrVJ+58S37pRVtCWXVnpj2UeSWzsS19zblyt7BX/qv6//3MxdBG7e9BR9uk4WsFhkgFJZFSWTh8ByM8cTtrdsjSlA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+101830+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1679690999613541.4837373208806; Fri, 24 Mar 2023 13:49:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id NdLmYY1788612xTBDIt7KYFp; Fri, 24 Mar 2023 13:49:59 -0700 X-Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.8297.1679690998674627490 for ; Fri, 24 Mar 2023 13:49:58 -0700 X-Received: from localhost.localdomain (unknown [47.201.8.94]) by linux.microsoft.com (Postfix) with ESMTPSA id 802EF20FC45C; Fri, 24 Mar 2023 13:49:57 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 802EF20FC45C From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Erich McMillan , Liming Gao , Michael D Kinney , Michael Kubacki , Zhiguang Liu Subject: [edk2-devel] [PATCH v6 06/12] MdePkg: Fix conditionally uninitialized variables Date: Fri, 24 Mar 2023 16:48:32 -0400 Message-Id: <20230324204838.1485-7-mikuback@linux.microsoft.com> In-Reply-To: <20230324204838.1485-1-mikuback@linux.microsoft.com> References: <20230324204838.1485-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,mikuback@linux.microsoft.com X-Gm-Message-State: CNsHhrwyAdsQ05eHmy1uBLXTx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679690999; bh=DjA5DoEFbZID44KD6VTrwmSDVaA4MPUvi0vnSq26Wbk=; h=Cc:Date:From:Reply-To:Subject:To; b=YBa7N0F6f1P2HsI44VoLZs/q9Ak9C4RW3iOiBlFU3rCRqkzsJ1SM1I/Ihw/cWFVlO78 MczBTWxLLiVgZzzCrFwUPx27J3JldJVdvLX7Rq23M+4Lm1BDfok55I75TTUaL9nRkSM7C VfrOTcmFbkt0VxKD29TDO4FGas4ExSxGrrE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679691001467100002 Content-Type: text/plain; charset="utf-8" From: Michael Kubacki Fixes CodeQL alerts for CWE-457: https://cwe.mitre.org/data/definitions/457.html Note that this change affects the actual return value from the following functions. The functions documented that if an integer overflow occurred, MAX_UINTN would be returned. They were implemented to actually return an undefined value from the stack. This change makes the function follow its description. However, this is technically different than what callers may have previously expected. MdePkg/Library/BaseLib/String.c: - StrDecimalToUintn() - StrDecimalToUint64() - StrHexToUintn() - StrHexToUint64() - AsciiStrDecimalToUintn() - AsciiStrDecimalToUint64() - AsciiStrHexToUintn() - AsciiStrHexToUint64() Cc: Erich McMillan Cc: Liming Gao Cc: Michael D Kinney Cc: Michael Kubacki Cc: Zhiguang Liu Co-authored-by: Erich McMillan Signed-off-by: Michael Kubacki Reviewed-by: Liming Gao --- MdePkg/Library/BaseLib/String.c | 40 ++++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/Strin= g.c index 98e6d31463e0..637c96e7b31b 100644 --- a/MdePkg/Library/BaseLib/String.c +++ b/MdePkg/Library/BaseLib/String.c @@ -408,7 +408,10 @@ StrDecimalToUintn ( { UINTN Result; =20 - StrDecimalToUintnS (String, (CHAR16 **)NULL, &Result); + if (RETURN_ERROR (StrDecimalToUintnS (String, (CHAR16 **)NULL, &Result))= ) { + return MAX_UINTN; + } + return Result; } =20 @@ -454,7 +457,10 @@ StrDecimalToUint64 ( { UINT64 Result; =20 - StrDecimalToUint64S (String, (CHAR16 **)NULL, &Result); + if (RETURN_ERROR (StrDecimalToUint64S (String, (CHAR16 **)NULL, &Result)= )) { + return MAX_UINT64; + } + return Result; } =20 @@ -501,7 +507,10 @@ StrHexToUintn ( { UINTN Result; =20 - StrHexToUintnS (String, (CHAR16 **)NULL, &Result); + if (RETURN_ERROR (StrHexToUintnS (String, (CHAR16 **)NULL, &Result))) { + return MAX_UINTN; + } + return Result; } =20 @@ -548,7 +557,10 @@ StrHexToUint64 ( { UINT64 Result; =20 - StrHexToUint64S (String, (CHAR16 **)NULL, &Result); + if (RETURN_ERROR (StrHexToUint64S (String, (CHAR16 **)NULL, &Result))) { + return MAX_UINT64; + } + return Result; } =20 @@ -989,7 +1001,10 @@ AsciiStrDecimalToUintn ( { UINTN Result; =20 - AsciiStrDecimalToUintnS (String, (CHAR8 **)NULL, &Result); + if (RETURN_ERROR (AsciiStrDecimalToUintnS (String, (CHAR8 **)NULL, &Resu= lt))) { + return MAX_UINTN; + } + return Result; } =20 @@ -1031,7 +1046,10 @@ AsciiStrDecimalToUint64 ( { UINT64 Result; =20 - AsciiStrDecimalToUint64S (String, (CHAR8 **)NULL, &Result); + if (RETURN_ERROR (AsciiStrDecimalToUint64S (String, (CHAR8 **)NULL, &Res= ult))) { + return MAX_UINT64; + } + return Result; } =20 @@ -1077,7 +1095,10 @@ AsciiStrHexToUintn ( { UINTN Result; =20 - AsciiStrHexToUintnS (String, (CHAR8 **)NULL, &Result); + if (RETURN_ERROR (AsciiStrHexToUintnS (String, (CHAR8 **)NULL, &Result))= ) { + return MAX_UINTN; + } + return Result; } =20 @@ -1123,7 +1144,10 @@ AsciiStrHexToUint64 ( { UINT64 Result; =20 - AsciiStrHexToUint64S (String, (CHAR8 **)NULL, &Result); + if (RETURN_ERROR (AsciiStrHexToUint64S (String, (CHAR8 **)NULL, &Result)= )) { + return MAX_UINT64; + } + return Result; } =20 --=20 2.40.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#101830): https://edk2.groups.io/g/devel/message/101830 Mute This Topic: https://groups.io/mt/97832901/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-