OcStringLib: Fix OcStrStrLength to match equal strings

This commit is contained in:
vit9696 2020-05-06 00:02:20 +03:00
parent 6336f034ca
commit ef1c9b02f2
3 changed files with 66 additions and 21 deletions

View File

@ -189,7 +189,7 @@ InternalGetAppleRecoveryName (
}
UnicodeSPrint (SystemVersionPath, SystemVersionPathSize, L"%sSystemVersion.plist", BootDirectoryName);
DEBUG ((DEBUG_INFO, "Trying to get recovery from %s\n", SystemVersionPath));
DEBUG ((DEBUG_INFO, "OCB: Trying to get recovery from %s\n", SystemVersionPath));
SystemVersionData = (CHAR8 *) ReadFile (FileSystem, SystemVersionPath, &SystemVersionDataSize, BASE_1MB);
FreePool (SystemVersionPath);

View File

@ -341,12 +341,33 @@ AddBootEntryOnFileSystem (
OC_BOOT_ENTRY_TYPE EntryType;
LIST_ENTRY *Link;
OC_BOOT_ENTRY *ExistingEntry;
CHAR16 *TextDevicePath;
BOOLEAN IsFolder;
DebugPrintDevicePath (DEBUG_INFO, "OCB: Adding entry", DevicePath);
EntryType = OcGetBootDevicePathType (DevicePath, &IsFolder);
DEBUG_CODE_BEGIN ();
if (DevicePath != NULL) {
TextDevicePath = ConvertDevicePathToText (DevicePath, TRUE, FALSE);
} else {
TextDevicePath = NULL;
}
DEBUG ((
DEBUG_INFO,
"OCB: Adding entry type (T:%u|F:%d) - %s\n",
EntryType,
IsFolder,
OC_HUMAN_STRING (TextDevicePath)
));
if (TextDevicePath != NULL) {
FreePool (TextDevicePath);
}
DEBUG_CODE_END ();
//
// Mark self recovery presence.
//

View File

@ -139,31 +139,55 @@ OcStriStr (
CONST CHAR16 *
OcStrStrLength (
IN CONST CHAR16 *String,
IN UINTN StringLength,
IN CONST CHAR16 *SearchString,
IN UINTN SearchStringLength
CONST CHAR16 *String,
UINTN StringLength,
CONST CHAR16 *SearchString,
UINTN SearchStringLength
)
{
UINTN RestLen;
UINTN Index;
INTN CmpResult;
BOOLEAN Overflowed;
UINTN Index;
UINTN Index2;
UINTN Index3;
INTN CmpResult;
CONST CHAR16 *Y;
CONST CHAR16 *X;
Overflowed = OcOverflowSubUN (StringLength, SearchStringLength, &RestLen);
if (Overflowed) {
//
// REF: http://www-igm.univ-mlv.fr/~lecroq/string/node13.html#SECTION00130
//
if (SearchStringLength > StringLength
|| SearchStringLength == 0
|| StringLength == 0) {
return NULL;
}
for (Index = 0; Index < RestLen; ++Index) {
CmpResult = CompareMem (
&String[Index],
SearchString,
(SearchStringLength + 1) * sizeof (*SearchString)
);
if (CmpResult == 0) {
return &String[Index];
Y = (CONST CHAR16 *) String;
X = (CONST CHAR16 *) SearchString;
if (X[0] == X[1]) {
Index2 = 2;
Index3 = 1;
} else {
Index2 = 1;
Index3 = 2;
}
if (SearchStringLength > 1) {
while (Index <= StringLength - SearchStringLength) {
if (X[1] != Y[Index+1]) {
Index += Index2;
} else {
CmpResult = CompareMem (X+2, Y+Index+2, (SearchStringLength - 2) * sizeof (*SearchString));
if (CmpResult == 0 && X[0] == Y[Index]) {
return &Y[Index];
}
Index += Index3;
}
}
} else {
return ScanMem16 (String, StringLength * sizeof (*SearchString), *SearchString);
}
return NULL;