]> code.delx.au - refind/commitdiff
Extra protections against action on NULL strings.
authorsrs5694 <srs5694@users.sourceforge.net>
Thu, 24 Jan 2013 04:10:05 +0000 (23:10 -0500)
committersrs5694 <srs5694@users.sourceforge.net>
Thu, 24 Jan 2013 04:10:05 +0000 (23:10 -0500)
refind/config.c
refind/lib.c

index ffe1970f562dc5b7a1858a9d14f1724f07dee382..88388b5b190351d302e0719643d40faa86ac254d 100644 (file)
@@ -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()
index 8235feab84d444375ef9febda95084f447f7008d..dadce367e57666cac4eab59a72ff415b9affdc10 100644 (file)
@@ -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++) {