Skip to content

Commit

Permalink
Fix some warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
jief666 committed Feb 6, 2021
1 parent 78708c2 commit 0354dc9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Include/Acidanthera/Library/OcAfterBootCompatLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#ifndef OC_AFTER_BOOT_COMPAT_LIB_H
#define OC_AFTER_BOOT_COMPAT_LIB_H

#include <Uefi/UefiSpec.h> // for EFI_EVENT_NOTIFY

/**
Apple Boot Compatibility layer configuration.
**/
Expand Down
15 changes: 8 additions & 7 deletions Library/OcMiscLib/DataPatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ FindPattern (

ASSERT (DataOff >= 0);

if (PatternSize == 0 || DataSize == 0 || (DataOff < 0) || (UINT32)DataOff >= DataSize || DataSize - DataOff < PatternSize) {
if (PatternSize == 0 || DataSize == 0 || (DataOff < 0) || (UINT32)DataOff >= DataSize || DataSize - (UINT32)DataOff < PatternSize) {
return -1;
}

while (DataOff + PatternSize < DataSize) {
while ((UINT32)DataOff + PatternSize < DataSize) {
Matches = TRUE;
for (Index = 0; Index < PatternSize; ++Index) {
if ((PatternMask == NULL && Data[DataOff + Index] != Pattern[Index])
|| (PatternMask != NULL && (Data[DataOff + Index] & PatternMask[Index]) != Pattern[Index])) {
if ((PatternMask == NULL && Data[(UINT32)DataOff + Index] != Pattern[Index])
|| (PatternMask != NULL && (Data[(UINT32)DataOff + Index] & PatternMask[Index]) != Pattern[Index])) {
Matches = FALSE;
break;
}
Expand All @@ -106,6 +106,7 @@ FindPattern (
if (Matches) {
return DataOff;
}
// Theoretically, DataOff can overflow because DataSize is UINT32.
++DataOff;
}

Expand Down Expand Up @@ -169,7 +170,7 @@ ApplyPatch (
}
AsciiSPrint(buf, length, "%a(", buf );
for (UINTN Index = 0; Index < PatternSize; ++Index) {
AsciiSPrint(buf, length, "%a%02X", buf, Data[DataOff + Index]);
AsciiSPrint(buf, length, "%a%02X", buf, Data[(UINT32)DataOff + Index]); // Safe cast, DataOff is >= 0
}
AsciiSPrint(buf, length, "%a)", buf );
}
Expand All @@ -179,7 +180,7 @@ ApplyPatch (
CopyMem (&Data[DataOff], (void*)Replace, PatternSize);
} else {
for (UINTN Index = 0; Index < PatternSize; ++Index) {
Data[DataOff + Index] = (Data[DataOff + Index] & ~ReplaceMask[Index]) | (Replace[Index] & ReplaceMask[Index]);
Data[(UINT32)DataOff + Index] = (Data[(UINT32)DataOff + Index] & ~ReplaceMask[Index]) | (Replace[Index] & ReplaceMask[Index]); // Safe cast, DataOff is >= 0
}
}

Expand All @@ -193,7 +194,7 @@ ApplyPatch (
}
AsciiSPrint(buf, length, "%a(", buf );
for (UINTN Index = 0; Index < PatternSize; ++Index) {
AsciiSPrint(buf, length, "%a%02X", buf, Data[DataOff + Index]);
AsciiSPrint(buf, length, "%a%02X", buf, Data[(UINT32)DataOff + Index]); // Safe cast, DataOff is >= 0
}
AsciiSPrint(buf, length, "%a)", buf );
}
Expand Down

0 comments on commit 0354dc9

Please sign in to comment.