From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.60.1668015203223395390 for ; Wed, 09 Nov 2022 09:33:23 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=W/N0YRFt; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from localhost.localdomain (unknown [47.201.8.94]) by linux.microsoft.com (Postfix) with ESMTPSA id 20C4520C28B1; Wed, 9 Nov 2022 09:33:22 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 20C4520C28B1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1668015202; bh=DEXeboqG36hx1WdEd5hPsbCadfXyWbMR8Wcvg6uuxAY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W/N0YRFtsr8oIPvz+f8mFTnFSAO78NVf1pmvfMSJWYWDKl0D5SCCVT/wCDJEGfJhV 0YNYNCJUchSaCHAe4GLYrvfyo6H8SEFuiaavKAsfQxUdoVEoTJuuFlRXRtdIYxjBmK 5UqDY2GDARYRhw4iY6ITvh83eKZHRWUcqvMS5Kjs= From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Erich McMillan , Liming Gao , Michael D Kinney , Michael Kubacki , Zhiguang Liu Subject: [PATCH v1 06/12] MdePkg: Fix conditionally uninitialized variables Date: Wed, 9 Nov 2022 12:32:40 -0500 Message-Id: <20221109173246.174-7-mikuback@linux.microsoft.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20221109173246.174-1-mikuback@linux.microsoft.com> References: <20221109173246.174-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Kubacki Fixes CodeQL alerts for CWE-457: https://cwe.mitre.org/data/definitions/457.html 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 --- MdePkg/Library/BaseLib/String.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/Str= ing.c index 98e6d31463e0..0ff0454b9d98 100644 --- a/MdePkg/Library/BaseLib/String.c +++ b/MdePkg/Library/BaseLib/String.c @@ -6,6 +6,7 @@ =20 **/ =20 +#include #include "BaseLibInternals.h" =20 /** @@ -408,7 +409,8 @@ StrDecimalToUintn ( { UINTN Result; =20 - StrDecimalToUintnS (String, (CHAR16 **)NULL, &Result); + Result =3D !EFI_ERROR (StrDecimalToUintnS (String, (CHAR16 **)NULL, &R= esult)) ? Result : MAX_UINTN; + return Result; } =20 @@ -454,7 +456,8 @@ StrDecimalToUint64 ( { UINT64 Result; =20 - StrDecimalToUint64S (String, (CHAR16 **)NULL, &Result); + Result =3D !EFI_ERROR (StrDecimalToUint64S (String, (CHAR16 **)NULL, &= Result)) ? Result : MAX_UINT64; + return Result; } =20 @@ -501,7 +504,8 @@ StrHexToUintn ( { UINTN Result; =20 - StrHexToUintnS (String, (CHAR16 **)NULL, &Result); + Result =3D !EFI_ERROR (StrHexToUintnS (String, (CHAR16 **)NULL, &Resul= t)) ? Result : MAX_UINTN; + return Result; } =20 @@ -548,7 +552,7 @@ StrHexToUint64 ( { UINT64 Result; =20 - StrHexToUint64S (String, (CHAR16 **)NULL, &Result); + Result =3D !EFI_ERROR (StrHexToUint64S (String, (CHAR16 **)NULL, &Resu= lt)) ? Result : MAX_UINT64; return Result; } =20 @@ -989,7 +993,7 @@ AsciiStrDecimalToUintn ( { UINTN Result; =20 - AsciiStrDecimalToUintnS (String, (CHAR8 **)NULL, &Result); + Result =3D !EFI_ERROR (AsciiStrDecimalToUintnS (String, (CHAR8 **)NULL= , &Result)) ? Result : MAX_UINTN; return Result; } =20 @@ -1031,7 +1035,7 @@ AsciiStrDecimalToUint64 ( { UINT64 Result; =20 - AsciiStrDecimalToUint64S (String, (CHAR8 **)NULL, &Result); + Result =3D !EFI_ERROR (AsciiStrDecimalToUint64S (String, (CHAR8 **)NUL= L, &Result)) ? Result : MAX_UINT64; return Result; } =20 @@ -1077,7 +1081,7 @@ AsciiStrHexToUintn ( { UINTN Result; =20 - AsciiStrHexToUintnS (String, (CHAR8 **)NULL, &Result); + Result =3D !EFI_ERROR (AsciiStrHexToUintnS (String, (CHAR8 **)NULL, &R= esult)) ? Result : MAX_UINTN; return Result; } =20 @@ -1123,7 +1127,7 @@ AsciiStrHexToUint64 ( { UINT64 Result; =20 - AsciiStrHexToUint64S (String, (CHAR8 **)NULL, &Result); + Result =3D !EFI_ERROR (AsciiStrHexToUint64S (String, (CHAR8 **)NULL, &= Result)) ? Result : MAX_UINT64; return Result; } =20 --=20 2.28.0.windows.1