From mboxrd@z Thu Jan 1 00:00:00 1970 Subject: [PATCH] SecurityPkg/Library/HashLibBaseCryptoRouter: Fix NULL_RETURNS Coverity issue To: devel@edk2.groups.io From: "Ranbir Singh" X-Originating-Location: Bengaluru, Karnataka, IN (122.172.85.38) X-Originating-Platform: Windows Chrome 108 User-Agent: GROUPS.IO Web Poster MIME-Version: 1.0 Date: Wed, 04 Jan 2023 01:02:16 -0800 Message-ID: Content-Type: multipart/alternative; boundary="S6FY69ikGJnfR4yTSY3u" --S6FY69ikGJnfR4yTSY3u Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable In file SecurityPkg/Library/HashLibBaseCryptoRouter/ HashLibBaseCryptoRouterPei.c, the function CheckSupportedHashMaskMismatch calls InternalGetHashInterfaceHob and stores return value in HashInterfaceHobLast. Thereafter, it does ASSERT (HashInterfaceHobLast !=3D NULL); but this comes into play only in DEBUG mode. In Release mode, the code continues to proceed to dereferencing "HashInterfaceHobLast" which will lead to CRASH if HashInterfaceHobLast is NULL. Hence, for safety add HashInterfaceHobLast NULL pointer check before accessing further field values. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4225 Signed-off-by: Ranbir Singh --- .../HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c=C2=A0 =C2=A0 =C2= =A0 =C2=A0| 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoR= outerPei.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoR= outerPei.c index eeb424b6c3..0c8315ed03 100644 --- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPe= i.c +++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPe= i.c @@ -108,7 +108,8 @@ CheckSupportedHashMaskMismatch ( HashInterfaceHobLast =3D InternalGetHashInterfaceHob (&gZeroGuid); ASSERT (HashInterfaceHobLast !=3D NULL); -=C2=A0 if ((HashInterfaceHobLast->SupportedHashMask !=3D 0) && +=C2=A0 if ((HashInterfaceHobLast !=3D NULL) && +=C2=A0 =C2=A0 =C2=A0 (HashInterfaceHobLast->SupportedHashMask !=3D 0) && (HashInterfaceHobCurrent->SupportedHashMask !=3D HashInterfaceHobLast->Supp= ortedHashMask)) { DEBUG (( -- 2.36.1.windows.1 --S6FY69ikGJnfR4yTSY3u Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
In file SecurityPkg/Library/HashLibBaseCryptoRouter/
HashLibBaseCryptoRouterPei.c, the function
CheckSupportedHashMaskMismatch calls InternalGetHashInterfaceHob and
stores return value in HashInterfaceHobLast. Thereafter, it does
 
  ASSERT (HashInterfaceHobLast !=3D NULL);
 
but this comes into play only in DEBUG mode. In Release mode, the
code continues to proceed to dereferencing "HashInterfaceHobLast"
which will lead to CRASH if HashInterfaceHobLast is NULL.
 
Hence, for safety add HashInterfaceHobLast NULL pointer check before
accessing further field values.
 
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4225
Signed-off-by: Ranbir Singh <Ranbir.Singh3@Dell.com>
---
 .../HashLibBaseCryptoRouter/HashLibBaseCryptoRouterPei.c  &= nbsp;    | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
 
diff --git a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCr= yptoRouterPei.c b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCr= yptoRouterPei.c
index eeb424b6c3..0c8315ed03 100644
--- a/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRou= terPei.c
+++ b/SecurityPkg/Library/HashLibBaseCryptoRouter/HashLibBaseCryptoRou= terPei.c
@@ -108,7 +108,8 @@ CheckSupportedHashMaskMismatch (
   HashInterfaceHobLast =3D InternalGetHashInterfaceHob (&am= p;gZeroGuid);
   ASSERT (HashInterfaceHobLast !=3D NULL);
 
-  if ((HashInterfaceHobLast->SupportedHashMask !=3D 0) &&= amp;
+  if ((HashInterfaceHobLast !=3D NULL) &&
+      (HashInterfaceHobLast->SupportedHashMask !=3D= 0) &&
       (HashInterfaceHobCurrent->SupportedHashM= ask !=3D HashInterfaceHobLast->SupportedHashMask))
   {
     DEBUG ((
--
2.36.1.windows.1
--S6FY69ikGJnfR4yTSY3u--