From 91581a9e34d50140b0f002c930f9b8fe64db095b Mon Sep 17 00:00:00 2001 From: Michael D Kinney Date: Wed, 23 Oct 2024 18:47:22 -0700 Subject: [PATCH] UefiCpuPkg/MtrrLib: Fix unit test read overflow Change conditional check to check the array index before reading the array member to prevent read past end of buffer. Signed-off-by: Michael D Kinney --- UefiCpuPkg/Library/MtrrLib/UnitTest/Support.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/MtrrLib/UnitTest/Support.c b/UefiCpuPkg/Library/MtrrLib/UnitTest/Support.c index 7df5b9745f906..ef3016db83221 100644 --- a/UefiCpuPkg/Library/MtrrLib/UnitTest/Support.c +++ b/UefiCpuPkg/Library/MtrrLib/UnitTest/Support.c @@ -745,7 +745,7 @@ GetNextDifferentElementInSortedArray ( UINT64 CurrentElement; CurrentElement = Array[Index]; - while (CurrentElement == Array[Index] && Index < Count) { + while ((Index < Count) && (CurrentElement == Array[Index])) { Index++; }