From: srs5694 Date: Thu, 24 Jan 2013 04:10:05 +0000 (-0500) Subject: Extra protections against action on NULL strings. X-Git-Url: https://code.delx.au/refind/commitdiff_plain/b8bc7202102818ae3fbda911bac51e2d56a9bc17 Extra protections against action on NULL strings. --- diff --git a/refind/config.c b/refind/config.c index ffe1970..88388b5 100644 --- a/refind/config.c +++ b/refind/config.c @@ -220,7 +220,6 @@ static CHAR16 *ReadLine(REFIT_FILE *File) static BOOLEAN KeepReading(IN OUT CHAR16 *p, IN OUT BOOLEAN *IsQuoted) { BOOLEAN MoreToRead = FALSE; CHAR16 *Temp = NULL; -// while (*p && *p != '"' && ((*p != ' ' && *p != '\t' && *p != '=' && *p != '#' && *p != ',') || IsQuoted)) { if ((p == NULL) || (IsQuoted == NULL)) return FALSE; @@ -351,7 +350,7 @@ VOID ReadConfig(CHAR16 *FileName) MyFreePool(GlobalConfig.DontScanDirs); if (SelfVolume) { if (SelfVolume->VolName) { - SelfPath = StrDuplicate(SelfVolume->VolName); + SelfPath = SelfVolume->VolName ? StrDuplicate(SelfVolume->VolName) : NULL; } else { SelfPath = AllocateZeroPool(256 * sizeof(CHAR16)); if (SelfPath != NULL) @@ -724,7 +723,7 @@ static LOADER_ENTRY * AddStanzaEntries(REFIT_FILE *File, REFIT_VOLUME *Volume, C } // if if (!DefaultsSet) - SetLoaderDefaults(Entry, L"\\EFI\\BOOT\\nemo.efi", CurrentVolume); // user included no entry; use bogus one + SetLoaderDefaults(Entry, L"\\EFI\\BOOT\\nemo.efi", CurrentVolume); // user included no "loader" line; use bogus one return(Entry); } // static VOID AddStanzaEntries() diff --git a/refind/lib.c b/refind/lib.c index 8235fea..dadce36 100644 --- a/refind/lib.c +++ b/refind/lib.c @@ -153,24 +153,26 @@ VOID CleanUpPathNameSlashes(IN OUT CHAR16 *PathName) { // after that string (after some cleanup) as the return value, and truncating the original // input value. // If InString contains no ")" character, this function leaves the original input string -// unmodified and also returns that string. +// unmodified and also returns that string. If InString is NULL, this function returns NULL. static CHAR16* SplitDeviceString(IN OUT CHAR16 *InString) { INTN i; CHAR16 *FileName = NULL; BOOLEAN Found = FALSE; - i = StrLen(InString) - 1; - while ((i >= 0) && (!Found)) { - if (InString[i] == L')') { - Found = TRUE; - FileName = StrDuplicate(&InString[i + 1]); - CleanUpPathNameSlashes(FileName); - InString[i + 1] = '\0'; - } // if - i--; - } // while - if (FileName == NULL) - FileName = StrDuplicate(InString); + if (InString != NULL) { + i = StrLen(InString) - 1; + while ((i >= 0) && (!Found)) { + if (InString[i] == L')') { + Found = TRUE; + FileName = StrDuplicate(&InString[i + 1]); + CleanUpPathNameSlashes(FileName); + InString[i + 1] = '\0'; + } // if + i--; + } // while + if (FileName == NULL) + FileName = StrDuplicate(InString); + } // if return FileName; } // static CHAR16* SplitDeviceString() @@ -1456,6 +1458,9 @@ CHAR16 *FindLastDirName(IN CHAR16 *Path) { UINTN i, StartOfElement = 0, EndOfElement = 0, PathLength, CopyLength; CHAR16 *Found = NULL; + if (Path == NULL) + return NULL; + PathLength = StrLen(Path); // Find start & end of target element for (i = 0; i < PathLength; i++) { @@ -1486,14 +1491,16 @@ CHAR16 *FindLastDirName(IN CHAR16 *Path) { // freeing the returned string's memory. CHAR16 *FindPath(IN CHAR16* FullPath) { UINTN i, LastBackslash = 0; - CHAR16 *PathOnly; + CHAR16 *PathOnly = NULL; - for (i = 0; i < StrLen(FullPath); i++) { - if (FullPath[i] == '\\') - LastBackslash = i; - } // for - PathOnly = StrDuplicate(FullPath); - PathOnly[LastBackslash] = 0; + if (FullPath != NULL) { + for (i = 0; i < StrLen(FullPath); i++) { + if (FullPath[i] == '\\') + LastBackslash = i; + } // for + PathOnly = StrDuplicate(FullPath); + PathOnly[LastBackslash] = 0; + } // if return (PathOnly); } @@ -1566,6 +1573,9 @@ CHAR16 *FindNumbers(IN CHAR16 *InString) { UINTN i, StartOfElement, EndOfElement = 0, InLength, CopyLength; CHAR16 *Found = NULL; + if (InString == NULL) + return NULL; + InLength = StartOfElement = StrLen(InString); // Find start & end of target element for (i = 0; i < InLength; i++) {