ocvalidate: Ensure the size of Data and Mask

This commit is contained in:
PMheart 2021-06-13 16:04:27 +08:00
parent a30fd31b8a
commit aaab599b96
2 changed files with 15 additions and 8 deletions

View File

@ -314,17 +314,22 @@ BOOLEAN
DataHasProperMasking (
IN CONST VOID *Data,
IN CONST VOID *Mask,
IN UINTN Size
IN UINTN DataSize,
IN UINTN MaskSize
)
{
CONST UINT8 *ByteData;
CONST UINT8 *ByteMask;
UINTN Index;
ByteData = Data;
ByteMask = Mask;
if (DataSize != MaskSize) {
return FALSE;
}
for (Index = 0; Index < Size; ++Index) {
ByteData = (CONST UINT8 *) Data;
ByteMask = (CONST UINT8 *) Mask;
for (Index = 0; Index < DataSize; ++Index) {
//
// Mask should only be set when corresponding bits on Data are inactive.
//
@ -384,7 +389,7 @@ ValidatePatch (
FindSize
));
++ErrorCount;
} else if (!DataHasProperMasking (Find, Mask, FindSize)) {
} else if (!DataHasProperMasking (Find, Mask, FindSize, MaskSize)) {
//
// If Mask is set without corresponding bits being active for Find, then error.
//
@ -412,7 +417,7 @@ ValidatePatch (
ReplaceSize
));
++ErrorCount;
} else if (!DataHasProperMasking (Replace, ReplaceMask, ReplaceSize)) {
} else if (!DataHasProperMasking (Replace, ReplaceMask, ReplaceSize, ReplaceMaskSize)) {
//
// If ReplaceMask is set without corresponding bits being active for Replace, then error.
//

View File

@ -139,7 +139,8 @@ AsciiGuidIsLegal (
@param[in] Data Data to be checked.
@param[in] Mask Mask to be applied to Data.
@param[in] Size Size of Data and Mask.
@param[in] DataSize Size of Data.
@param[in] MaskSize Size of Mask.
@retval TRUE If corresponding bits of Mask to Data are active (set to non-zero).
**/
@ -147,7 +148,8 @@ BOOLEAN
DataHasProperMasking (
IN CONST VOID *Data,
IN CONST VOID *Mask,
IN UINTN Size
IN UINTN DataSize,
IN UINTN MaskSize
);
/**