X-Git-Url: https://code.delx.au/refind/blobdiff_plain/1f5e6865fb9bf8ebb78b4818a6d54440c7c4004a..8e261d06ab599ac8eb4d0108a88c30a0a1b8f814:/refind/lib.c diff --git a/refind/lib.c b/refind/lib.c index 3c61782..f5037c5 100644 --- a/refind/lib.c +++ b/refind/lib.c @@ -79,8 +79,9 @@ static VOID UninitVolumes(VOID); // Converts forward slashes to backslashes and removes duplicate slashes. // Necessary because some (buggy?) EFI implementations produce "\/" strings -// in pathnames. -static VOID CleanUpPathNameSlashes(IN OUT CHAR16 *PathName) { +// in pathnames and because some user inputs can produce duplicate directory +// separators +VOID CleanUpPathNameSlashes(IN OUT CHAR16 *PathName) { CHAR16 *NewName; UINTN i, j = 0; BOOLEAN LastWasSlash = FALSE; @@ -293,11 +294,11 @@ VOID ExtractLegacyLoaderPaths(EFI_DEVICE_PATH **PathList, UINTN MaxPaths, EFI_DE } if (Seen) continue; - + PathList[PathCount++] = AppendDevicePath(DevicePath, LegacyLoaderMediaPath); } FreePool(Handles); - + if (HardcodedPathList) { for (HardcodedIndex = 0; HardcodedPathList[HardcodedIndex] && PathCount < MaxPaths; HardcodedIndex++) PathList[PathCount++] = HardcodedPathList[HardcodedIndex]; @@ -316,17 +317,17 @@ static VOID ScanVolumeBootcode(IN OUT REFIT_VOLUME *Volume, OUT BOOLEAN *Bootabl UINTN i; MBR_PARTITION_INFO *MbrTable; BOOLEAN MbrTableFound; - + Volume->HasBootCode = FALSE; Volume->OSIconName = NULL; Volume->OSName = NULL; *Bootable = FALSE; - + if (Volume->BlockIO == NULL) return; if (Volume->BlockIO->Media->BlockSize > SECTOR_SIZE) return; // our buffer is too small... - + // look at the boot sector (this is used for both hard disks and El Torito images!) Status = refit_call5_wrapper(Volume->BlockIO->ReadBlocks, Volume->BlockIO, Volume->BlockIO->Media->MediaId, @@ -579,7 +580,10 @@ static VOID ScanVolume(IN OUT REFIT_VOLUME *Volume) // open the root directory of the volume Volume->RootDir = LibOpenRoot(Volume->DeviceHandle); if (Volume->RootDir == NULL) { + Volume->IsReadable = FALSE; return; + } else { + Volume->IsReadable = TRUE; } // get volume name @@ -1073,8 +1077,8 @@ VOID MergeStrings(IN OUT CHAR16 **First, IN CHAR16 *Second, CHAR16 AddChar) { if (Second != NULL) Length2 = StrLen(Second); NewString = AllocatePool(sizeof(CHAR16) * (Length1 + Length2 + 2)); - NewString[0] = L'\0'; if (NewString != NULL) { + NewString[0] = L'\0'; if (*First != NULL) { StrCat(NewString, *First); if (AddChar) { @@ -1082,7 +1086,7 @@ VOID MergeStrings(IN OUT CHAR16 **First, IN CHAR16 *Second, CHAR16 AddChar) { NewString[Length1 + 1] = 0; } // if (AddChar) } // if (*First != NULL) - if (First != NULL) + if (Second != NULL) StrCat(NewString, Second); FreePool(*First); *First = NewString; @@ -1171,7 +1175,7 @@ CHAR16 *FindNumbers(IN CHAR16 *InString) { // Find the #Index element (numbered from 0) in a comma-delimited string // of elements. -// Returns the found element, or NULL if Index is out of range of InString +// Returns the found element, or NULL if Index is out of range or InString // is NULL. CHAR16 *FindCommaDelimited(IN CHAR16 *InString, IN UINTN Index) { UINTN StartPos = 0, CurPos = 0; @@ -1194,10 +1198,10 @@ CHAR16 *FindCommaDelimited(IN CHAR16 *InString, IN UINTN Index) { else CurPos++; } // while + if (Index == 0) + FoundString = StrDuplicate(&InString[StartPos]); + if (FoundString != NULL) + FoundString[CurPos - StartPos] = 0; } // if - if (Index == 0) - FoundString = StrDuplicate(&InString[StartPos]); - if (FoundString != NULL) - FoundString[CurPos - StartPos] = 0; return (FoundString); } // CHAR16 *FindCommaDelimited()