From a48caeebbab99e22bfd4072829ecaf553cc92c9c Mon Sep 17 00:00:00 2001 From: xli24 Date: Tue, 10 Aug 2010 08:57:36 +0000 Subject: [PATCH] Add boundary check against variable MTRR count. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10787 6f19259b-4bc3-4df7-8a09-765794883524 --- UefiCpuPkg/Library/MtrrLib/MtrrLib.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c index 1f2604ab8b..fca9258ed7 100644 --- a/UefiCpuPkg/Library/MtrrLib/MtrrLib.c +++ b/UefiCpuPkg/Library/MtrrLib/MtrrLib.c @@ -93,11 +93,16 @@ GetVariableMtrrCount ( VOID ) { + UINT32 VariableMtrrCount; + if (!IsMtrrSupported ()) { return 0; } - return (UINT32)(AsmReadMsr64 (MTRR_LIB_IA32_MTRR_CAP) & MTRR_LIB_IA32_MTRR_CAP_VCNT_MASK); + VariableMtrrCount = (UINT32)(AsmReadMsr64 (MTRR_LIB_IA32_MTRR_CAP) & MTRR_LIB_IA32_MTRR_CAP_VCNT_MASK); + ASSERT (VariableMtrrCount <= MTRR_NUMBER_OF_VARIABLE_MTRR); + + return VariableMtrrCount; } /**