ShellPkg: Refactor string manipulation
This patch replaces StrCpy with StrnCpy or refactors out the usage of StrCpy through some other means. This patch replaces StrCat with StrnCat or refactors out the usage of StrCat through some other means. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16038 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
		@@ -509,21 +509,20 @@ FileInterfaceStdInRead(
 | 
				
			|||||||
        if (StrStr(CurrentString + TabPos, L":") == NULL) {
 | 
					        if (StrStr(CurrentString + TabPos, L":") == NULL) {
 | 
				
			||||||
          Cwd = ShellInfoObject.NewEfiShellProtocol->GetCurDir(NULL);
 | 
					          Cwd = ShellInfoObject.NewEfiShellProtocol->GetCurDir(NULL);
 | 
				
			||||||
          if (Cwd != NULL) {
 | 
					          if (Cwd != NULL) {
 | 
				
			||||||
            StrCpy(TabStr, Cwd);
 | 
					            StrnCpy(TabStr, Cwd, (*BufferSize)/sizeof(CHAR16) - 1);
 | 
				
			||||||
            if (TabStr[StrLen(TabStr)-1] == L'\\' && *(CurrentString + TabPos) == L'\\' ) {
 | 
					            if (TabStr[StrLen(TabStr)-1] == L'\\' && *(CurrentString + TabPos) == L'\\' ) {
 | 
				
			||||||
              TabStr[StrLen(TabStr)-1] = CHAR_NULL;
 | 
					              TabStr[StrLen(TabStr)-1] = CHAR_NULL;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            StrnCat(TabStr, CurrentString + TabPos, (StringLen - TabPos) * sizeof (CHAR16));
 | 
					            StrnCat(TabStr, CurrentString + TabPos, (StringLen - TabPos) * sizeof (CHAR16));
 | 
				
			||||||
          } else {
 | 
					          } else {
 | 
				
			||||||
            StrCpy(TabStr, L"");
 | 
					            *TabStr = CHAR_NULL;
 | 
				
			||||||
            StrnCat(TabStr, CurrentString + TabPos, (StringLen - TabPos) * sizeof (CHAR16));
 | 
					            StrnCat(TabStr, CurrentString + TabPos, (StringLen - TabPos) * sizeof (CHAR16));
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
          StrCpy(TabStr, CurrentString + TabPos);
 | 
					          StrnCpy(TabStr, CurrentString + TabPos, (*BufferSize)/sizeof(CHAR16) - 1);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        StrCat(TabStr, L"*");
 | 
					        StrnCat(TabStr, L"*", (*BufferSize)/sizeof(CHAR16) - 1 - StrLen(TabStr));
 | 
				
			||||||
        FoundFileList = NULL;
 | 
					        FoundFileList = NULL;
 | 
				
			||||||
//        TabStr = PathCleanUpDirectories(TabStr);
 | 
					 | 
				
			||||||
        Status  = ShellInfoObject.NewEfiShellProtocol->FindFiles(TabStr, &FoundFileList);
 | 
					        Status  = ShellInfoObject.NewEfiShellProtocol->FindFiles(TabStr, &FoundFileList);
 | 
				
			||||||
        for ( TempStr = CurrentString
 | 
					        for ( TempStr = CurrentString
 | 
				
			||||||
            ; *TempStr == L' '
 | 
					            ; *TempStr == L' '
 | 
				
			||||||
@@ -1168,7 +1167,7 @@ CreateFileInterfaceEnv(
 | 
				
			|||||||
  EnvFileInterface->Delete      = FileInterfaceEnvDelete;
 | 
					  EnvFileInterface->Delete      = FileInterfaceEnvDelete;
 | 
				
			||||||
  EnvFileInterface->Read        = FileInterfaceEnvRead;
 | 
					  EnvFileInterface->Read        = FileInterfaceEnvRead;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  StrCpy(EnvFileInterface->Name, EnvName);
 | 
					  StrnCpy(EnvFileInterface->Name, EnvName, StrLen(EnvName));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  //
 | 
					  //
 | 
				
			||||||
  // Assign the different members for Volatile and Non-Volatile variables
 | 
					  // Assign the different members for Volatile and Non-Volatile variables
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -937,7 +937,7 @@ ProcessCommandLine(
 | 
				
			|||||||
        continue;
 | 
					        continue;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      ShellInfoObject.ShellInitSettings.FileName = AllocateZeroPool(StrSize(CurrentArg));
 | 
					      ShellInfoObject.ShellInitSettings.FileName = AllocateCopyPool(StrSize(CurrentArg), CurrentArg);
 | 
				
			||||||
      if (ShellInfoObject.ShellInitSettings.FileName == NULL) {
 | 
					      if (ShellInfoObject.ShellInitSettings.FileName == NULL) {
 | 
				
			||||||
        return (EFI_OUT_OF_RESOURCES);
 | 
					        return (EFI_OUT_OF_RESOURCES);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@@ -945,8 +945,6 @@ ProcessCommandLine(
 | 
				
			|||||||
      // We found `file-name`.
 | 
					      // We found `file-name`.
 | 
				
			||||||
      //
 | 
					      //
 | 
				
			||||||
      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup = 1;
 | 
					      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup = 1;
 | 
				
			||||||
 | 
					 | 
				
			||||||
      StrCpy (ShellInfoObject.ShellInitSettings.FileName, CurrentArg);
 | 
					 | 
				
			||||||
      LoopVar++;
 | 
					      LoopVar++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Add `file-name-options`
 | 
					      // Add `file-name-options`
 | 
				
			||||||
@@ -1027,10 +1025,10 @@ DoStartupScript(
 | 
				
			|||||||
    if (FileStringPath == NULL) {
 | 
					    if (FileStringPath == NULL) {
 | 
				
			||||||
      return (EFI_OUT_OF_RESOURCES);
 | 
					      return (EFI_OUT_OF_RESOURCES);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    StrCpy(FileStringPath, ShellInfoObject.ShellInitSettings.FileName);
 | 
					    StrnCpy(FileStringPath, ShellInfoObject.ShellInitSettings.FileName, NewSize/sizeof(CHAR16) -1);
 | 
				
			||||||
    if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {
 | 
					    if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {
 | 
				
			||||||
      StrCat(FileStringPath, L" ");
 | 
					      StrnCat(FileStringPath, L" ", NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);
 | 
				
			||||||
      StrCat(FileStringPath, ShellInfoObject.ShellInitSettings.FileOptions);
 | 
					      StrnCat(FileStringPath, ShellInfoObject.ShellInitSettings.FileOptions, NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    Status = RunCommand(FileStringPath, ExitStatus);
 | 
					    Status = RunCommand(FileStringPath, ExitStatus);
 | 
				
			||||||
    FreePool(FileStringPath);
 | 
					    FreePool(FileStringPath);
 | 
				
			||||||
@@ -1247,9 +1245,8 @@ AddLineToCommandHistory(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  Node = AllocateZeroPool(sizeof(BUFFER_LIST));
 | 
					  Node = AllocateZeroPool(sizeof(BUFFER_LIST));
 | 
				
			||||||
  ASSERT(Node != NULL);
 | 
					  ASSERT(Node != NULL);
 | 
				
			||||||
  Node->Buffer = AllocateZeroPool(StrSize(Buffer));
 | 
					  Node->Buffer = AllocateCopyPool(StrSize(Buffer), Buffer);
 | 
				
			||||||
  ASSERT(Node->Buffer != NULL);
 | 
					  ASSERT(Node->Buffer != NULL);
 | 
				
			||||||
  StrCpy(Node->Buffer, Buffer);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  InsertTailList(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Node->Link);
 | 
					  InsertTailList(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Node->Link);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1280,11 +1277,10 @@ ShellConvertAlias(
 | 
				
			|||||||
    return (EFI_SUCCESS);
 | 
					    return (EFI_SUCCESS);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  FreePool(*CommandString);
 | 
					  FreePool(*CommandString);
 | 
				
			||||||
  *CommandString = AllocateZeroPool(StrSize(NewString));
 | 
					  *CommandString = AllocateCopyPool(StrSize(NewString), NewString);
 | 
				
			||||||
  if (*CommandString == NULL) {
 | 
					  if (*CommandString == NULL) {
 | 
				
			||||||
    return (EFI_OUT_OF_RESOURCES);
 | 
					    return (EFI_OUT_OF_RESOURCES);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  StrCpy(*CommandString, NewString);
 | 
					 | 
				
			||||||
  return (EFI_SUCCESS);
 | 
					  return (EFI_SUCCESS);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1477,7 +1473,7 @@ ShellConvertVariables (
 | 
				
			|||||||
  //
 | 
					  //
 | 
				
			||||||
  // now do the replacements...
 | 
					  // now do the replacements...
 | 
				
			||||||
  //
 | 
					  //
 | 
				
			||||||
  NewCommandLine1 = AllocateZeroPool(NewSize);
 | 
					  NewCommandLine1 = AllocateCopyPool(NewSize, OriginalCommandLine);
 | 
				
			||||||
  NewCommandLine2 = AllocateZeroPool(NewSize);
 | 
					  NewCommandLine2 = AllocateZeroPool(NewSize);
 | 
				
			||||||
  ItemTemp        = AllocateZeroPool(ItemSize+(2*sizeof(CHAR16)));
 | 
					  ItemTemp        = AllocateZeroPool(ItemSize+(2*sizeof(CHAR16)));
 | 
				
			||||||
  if (NewCommandLine1 == NULL || NewCommandLine2 == NULL || ItemTemp == NULL) {
 | 
					  if (NewCommandLine1 == NULL || NewCommandLine2 == NULL || ItemTemp == NULL) {
 | 
				
			||||||
@@ -1486,16 +1482,15 @@ ShellConvertVariables (
 | 
				
			|||||||
    SHELL_FREE_NON_NULL(ItemTemp);
 | 
					    SHELL_FREE_NON_NULL(ItemTemp);
 | 
				
			||||||
    return (NULL);
 | 
					    return (NULL);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  StrCpy(NewCommandLine1, OriginalCommandLine);
 | 
					 | 
				
			||||||
  for (MasterEnvList = EfiShellGetEnv(NULL)
 | 
					  for (MasterEnvList = EfiShellGetEnv(NULL)
 | 
				
			||||||
    ;  MasterEnvList != NULL && *MasterEnvList != CHAR_NULL //&& *(MasterEnvList+1) != CHAR_NULL
 | 
					    ;  MasterEnvList != NULL && *MasterEnvList != CHAR_NULL
 | 
				
			||||||
    ;  MasterEnvList += StrLen(MasterEnvList) + 1
 | 
					    ;  MasterEnvList += StrLen(MasterEnvList) + 1
 | 
				
			||||||
   ){
 | 
					   ){
 | 
				
			||||||
    StrCpy(ItemTemp, L"%");
 | 
					    *ItemTemp = L'%';
 | 
				
			||||||
    StrCat(ItemTemp, MasterEnvList);
 | 
					    StrnCat(ItemTemp, MasterEnvList, ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1 - StrLen(ItemTemp));
 | 
				
			||||||
    StrCat(ItemTemp, L"%");
 | 
					    StrnCat(ItemTemp, L"%", ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1 - StrLen(ItemTemp));
 | 
				
			||||||
    ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, ItemTemp, EfiShellGetEnv(MasterEnvList), TRUE, FALSE);
 | 
					    ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, ItemTemp, EfiShellGetEnv(MasterEnvList), TRUE, FALSE);
 | 
				
			||||||
    StrCpy(NewCommandLine1, NewCommandLine2);
 | 
					    StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (CurrentScriptFile != NULL) {
 | 
					  if (CurrentScriptFile != NULL) {
 | 
				
			||||||
    for (AliasListNode = (ALIAS_LIST*)GetFirstNode(&CurrentScriptFile->SubstList)
 | 
					    for (AliasListNode = (ALIAS_LIST*)GetFirstNode(&CurrentScriptFile->SubstList)
 | 
				
			||||||
@@ -1503,7 +1498,7 @@ ShellConvertVariables (
 | 
				
			|||||||
      ;  AliasListNode = (ALIAS_LIST*)GetNextNode(&CurrentScriptFile->SubstList, &AliasListNode->Link)
 | 
					      ;  AliasListNode = (ALIAS_LIST*)GetNextNode(&CurrentScriptFile->SubstList, &AliasListNode->Link)
 | 
				
			||||||
   ){
 | 
					   ){
 | 
				
			||||||
    ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE);
 | 
					    ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE);
 | 
				
			||||||
    StrCpy(NewCommandLine1, NewCommandLine2);
 | 
					    StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //
 | 
					    //
 | 
				
			||||||
@@ -1516,7 +1511,7 @@ ShellConvertVariables (
 | 
				
			|||||||
  // Now cleanup any straggler intentionally ignored "%" characters
 | 
					  // Now cleanup any straggler intentionally ignored "%" characters
 | 
				
			||||||
  //
 | 
					  //
 | 
				
			||||||
  ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, L"^%", L"%", TRUE, FALSE);
 | 
					  ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, L"^%", L"%", TRUE, FALSE);
 | 
				
			||||||
  StrCpy(NewCommandLine1, NewCommandLine2);
 | 
					  StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  FreePool(NewCommandLine2);
 | 
					  FreePool(NewCommandLine2);
 | 
				
			||||||
  FreePool(ItemTemp);
 | 
					  FreePool(ItemTemp);
 | 
				
			||||||
@@ -1850,7 +1845,7 @@ IsValidSplit(
 | 
				
			|||||||
      return (EFI_OUT_OF_RESOURCES);
 | 
					      return (EFI_OUT_OF_RESOURCES);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    TempWalker = (CHAR16*)Temp;
 | 
					    TempWalker = (CHAR16*)Temp;
 | 
				
			||||||
    GetNextParameter(&TempWalker, &FirstParameter);
 | 
					    GetNextParameter(&TempWalker, &FirstParameter, StrSize(CmdLine));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (GetOperationType(FirstParameter) == Unknown_Invalid) {
 | 
					    if (GetOperationType(FirstParameter) == Unknown_Invalid) {
 | 
				
			||||||
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
 | 
					      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
 | 
				
			||||||
@@ -2018,7 +2013,7 @@ DoHelpUpdate(
 | 
				
			|||||||
  Walker = *CmdLine;
 | 
					  Walker = *CmdLine;
 | 
				
			||||||
  while(Walker != NULL && *Walker != CHAR_NULL) {
 | 
					  while(Walker != NULL && *Walker != CHAR_NULL) {
 | 
				
			||||||
    LastWalker = Walker;
 | 
					    LastWalker = Walker;
 | 
				
			||||||
    GetNextParameter(&Walker, &CurrentParameter);
 | 
					    GetNextParameter(&Walker, &CurrentParameter, StrSize(*CmdLine));
 | 
				
			||||||
    if (StrStr(CurrentParameter, L"-?") == CurrentParameter) {
 | 
					    if (StrStr(CurrentParameter, L"-?") == CurrentParameter) {
 | 
				
			||||||
      LastWalker[0] = L' ';
 | 
					      LastWalker[0] = L' ';
 | 
				
			||||||
      LastWalker[1] = L' ';
 | 
					      LastWalker[1] = L' ';
 | 
				
			||||||
@@ -2027,8 +2022,12 @@ DoHelpUpdate(
 | 
				
			|||||||
        Status = EFI_OUT_OF_RESOURCES;
 | 
					        Status = EFI_OUT_OF_RESOURCES;
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      StrCpy(NewCommandLine, L"help ");
 | 
					
 | 
				
			||||||
      StrCat(NewCommandLine, *CmdLine);
 | 
					      //
 | 
				
			||||||
 | 
					      // We know the space is sufficient since we just calculated it.
 | 
				
			||||||
 | 
					      //
 | 
				
			||||||
 | 
					      StrnCpy(NewCommandLine, L"help ", 5);
 | 
				
			||||||
 | 
					      StrnCat(NewCommandLine, *CmdLine, StrLen(*CmdLine));
 | 
				
			||||||
      SHELL_FREE_NON_NULL(*CmdLine);
 | 
					      SHELL_FREE_NON_NULL(*CmdLine);
 | 
				
			||||||
      *CmdLine = NewCommandLine;
 | 
					      *CmdLine = NewCommandLine;
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
@@ -2507,7 +2506,7 @@ RunCommand(
 | 
				
			|||||||
    return (EFI_OUT_OF_RESOURCES);
 | 
					    return (EFI_OUT_OF_RESOURCES);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  TempWalker = CleanOriginal;
 | 
					  TempWalker = CleanOriginal;
 | 
				
			||||||
  GetNextParameter(&TempWalker, &FirstParameter);
 | 
					  GetNextParameter(&TempWalker, &FirstParameter, StrSize(CleanOriginal));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  //
 | 
					  //
 | 
				
			||||||
  // Depending on the first parameter we change the behavior
 | 
					  // Depending on the first parameter we change the behavior
 | 
				
			||||||
@@ -2703,7 +2702,7 @@ RunScriptFileHandle (
 | 
				
			|||||||
      ; // conditional increment in the body of the loop
 | 
					      ; // conditional increment in the body of the loop
 | 
				
			||||||
  ){
 | 
					  ){
 | 
				
			||||||
    ASSERT(CommandLine2 != NULL);
 | 
					    ASSERT(CommandLine2 != NULL);
 | 
				
			||||||
    StrCpy(CommandLine2, NewScriptFile->CurrentCommand->Cl);
 | 
					    StrnCpy(CommandLine2, NewScriptFile->CurrentCommand->Cl, PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16)-1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //
 | 
					    //
 | 
				
			||||||
    // NULL out comments
 | 
					    // NULL out comments
 | 
				
			||||||
@@ -2722,7 +2721,7 @@ RunScriptFileHandle (
 | 
				
			|||||||
      //
 | 
					      //
 | 
				
			||||||
      // Due to variability in starting the find and replace action we need to have both buffers the same.
 | 
					      // Due to variability in starting the find and replace action we need to have both buffers the same.
 | 
				
			||||||
      //
 | 
					      //
 | 
				
			||||||
      StrCpy(CommandLine, CommandLine2);
 | 
					      StrnCpy(CommandLine, CommandLine2, PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16)-1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      //
 | 
					      //
 | 
				
			||||||
      // Remove the %0 to %9 from the command line (if we have some arguments)
 | 
					      // Remove the %0 to %9 from the command line (if we have some arguments)
 | 
				
			||||||
@@ -2774,7 +2773,7 @@ RunScriptFileHandle (
 | 
				
			|||||||
      Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%8", L"\"\"", FALSE, FALSE);
 | 
					      Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%8", L"\"\"", FALSE, FALSE);
 | 
				
			||||||
      Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%9", L"\"\"", FALSE, FALSE);
 | 
					      Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%9", L"\"\"", FALSE, FALSE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      StrCpy(CommandLine2, CommandLine);
 | 
					      StrnCpy(CommandLine2, CommandLine, PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16)-1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      LastCommand = NewScriptFile->CurrentCommand;
 | 
					      LastCommand = NewScriptFile->CurrentCommand;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -152,7 +152,7 @@ GetEnvironmentVariableList(
 | 
				
			|||||||
  if (VariableName == NULL) {
 | 
					  if (VariableName == NULL) {
 | 
				
			||||||
    return (EFI_OUT_OF_RESOURCES);
 | 
					    return (EFI_OUT_OF_RESOURCES);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  StrCpy(VariableName, L"");
 | 
					  *VariableName = CHAR_NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  while (!EFI_ERROR(Status)) {
 | 
					  while (!EFI_ERROR(Status)) {
 | 
				
			||||||
    NameSize = (UINTN)MaxVarSize;
 | 
					    NameSize = (UINTN)MaxVarSize;
 | 
				
			||||||
@@ -178,13 +178,12 @@ GetEnvironmentVariableList(
 | 
				
			|||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (!EFI_ERROR(Status) && VarList != NULL) {
 | 
					        if (!EFI_ERROR(Status) && VarList != NULL) {
 | 
				
			||||||
          VarList->Key = AllocateZeroPool(StrSize(VariableName));
 | 
					          VarList->Key = AllocateCopyPool(StrSize(VariableName), VariableName);
 | 
				
			||||||
          if (VarList->Key == NULL) {
 | 
					          if (VarList->Key == NULL) {
 | 
				
			||||||
            SHELL_FREE_NON_NULL(VarList->Val);
 | 
					            SHELL_FREE_NON_NULL(VarList->Val);
 | 
				
			||||||
            SHELL_FREE_NON_NULL(VarList);
 | 
					            SHELL_FREE_NON_NULL(VarList);
 | 
				
			||||||
            Status = EFI_OUT_OF_RESOURCES;
 | 
					            Status = EFI_OUT_OF_RESOURCES;
 | 
				
			||||||
          } else {
 | 
					          } else {
 | 
				
			||||||
            StrCpy(VarList->Key, VariableName);
 | 
					 | 
				
			||||||
            InsertTailList(ListHead, &VarList->Link);
 | 
					            InsertTailList(ListHead, &VarList->Link);
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -286,7 +285,6 @@ SetEnvironmentVariables(
 | 
				
			|||||||
  UINTN         CurrentCount;
 | 
					  UINTN         CurrentCount;
 | 
				
			||||||
  ENV_VAR_LIST  *VarList;
 | 
					  ENV_VAR_LIST  *VarList;
 | 
				
			||||||
  ENV_VAR_LIST  *Node;
 | 
					  ENV_VAR_LIST  *Node;
 | 
				
			||||||
  UINTN         NewSize;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  VarList = NULL;
 | 
					  VarList = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -307,20 +305,44 @@ SetEnvironmentVariables(
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    ASSERT(StrStr(CurrentString, L"=") != NULL);
 | 
					    ASSERT(StrStr(CurrentString, L"=") != NULL);
 | 
				
			||||||
    Node = AllocateZeroPool(sizeof(ENV_VAR_LIST));
 | 
					    Node = AllocateZeroPool(sizeof(ENV_VAR_LIST));
 | 
				
			||||||
    ASSERT(Node != NULL);
 | 
					    if (Node == NULL) {
 | 
				
			||||||
 | 
					      SetEnvironmentVariableList(&VarList->Link);
 | 
				
			||||||
 | 
					      return (EFI_OUT_OF_RESOURCES);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Node->Key = AllocateZeroPool((StrStr(CurrentString, L"=") - CurrentString + 1) * sizeof(CHAR16));
 | 
					    Node->Key = AllocateZeroPool((StrStr(CurrentString, L"=") - CurrentString + 1) * sizeof(CHAR16));
 | 
				
			||||||
    ASSERT(Node->Key != NULL);
 | 
					    if (Node->Key == NULL) {
 | 
				
			||||||
 | 
					      SHELL_FREE_NON_NULL(Node);
 | 
				
			||||||
 | 
					      SetEnvironmentVariableList(&VarList->Link);
 | 
				
			||||||
 | 
					      return (EFI_OUT_OF_RESOURCES);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //
 | 
				
			||||||
 | 
					    // Copy the string into the Key, leaving the last character allocated as NULL to terminate
 | 
				
			||||||
 | 
					    //
 | 
				
			||||||
    StrnCpy(Node->Key, CurrentString, StrStr(CurrentString, L"=") - CurrentString);
 | 
					    StrnCpy(Node->Key, CurrentString, StrStr(CurrentString, L"=") - CurrentString);
 | 
				
			||||||
    NewSize = StrSize(CurrentString);
 | 
					
 | 
				
			||||||
    NewSize -= StrLen(Node->Key) - 1;
 | 
					    //
 | 
				
			||||||
    Node->Val = AllocateZeroPool(NewSize);
 | 
					    // ValueSize = TotalSize - already removed size - size for '=' + size for terminator (the last 2 items cancel each other)
 | 
				
			||||||
    ASSERT(Node->Val != NULL);
 | 
					    //
 | 
				
			||||||
    StrCpy(Node->Val, CurrentString + StrLen(Node->Key) + 1);
 | 
					    Node->Val = AllocateCopyPool(StrSize(CurrentString) - StrSize(Node->Key), CurrentString + StrLen(Node->Key) + 1);
 | 
				
			||||||
 | 
					    if (Node->Val == NULL) {
 | 
				
			||||||
 | 
					      SHELL_FREE_NON_NULL(Node->Key);
 | 
				
			||||||
 | 
					      SHELL_FREE_NON_NULL(Node);
 | 
				
			||||||
 | 
					      SetEnvironmentVariableList(&VarList->Link);
 | 
				
			||||||
 | 
					      return (EFI_OUT_OF_RESOURCES);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Node->Atts = EFI_VARIABLE_BOOTSERVICE_ACCESS;
 | 
					    Node->Atts = EFI_VARIABLE_BOOTSERVICE_ACCESS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (VarList == NULL) {
 | 
					    if (VarList == NULL) {
 | 
				
			||||||
      VarList = AllocateZeroPool(sizeof(ENV_VAR_LIST));
 | 
					      VarList = AllocateZeroPool(sizeof(ENV_VAR_LIST));
 | 
				
			||||||
      ASSERT(VarList != NULL);
 | 
					      if (VarList == NULL) {
 | 
				
			||||||
 | 
					        SHELL_FREE_NON_NULL(Node->Key);
 | 
				
			||||||
 | 
					        SHELL_FREE_NON_NULL(Node->Val);
 | 
				
			||||||
 | 
					        SHELL_FREE_NON_NULL(Node);
 | 
				
			||||||
 | 
					        return (EFI_OUT_OF_RESOURCES);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      InitializeListHead(&VarList->Link);
 | 
					      InitializeListHead(&VarList->Link);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    InsertTailList(&VarList->Link, &Node->Link);
 | 
					    InsertTailList(&VarList->Link, &Node->Link);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
/** @file
 | 
					/** @file
 | 
				
			||||||
  Provides interface to shell MAN file parser.
 | 
					  Provides interface to shell MAN file parser.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
 | 
					  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
 | 
				
			||||||
  This program and the accompanying materials
 | 
					  This program and the accompanying materials
 | 
				
			||||||
  are licensed and made available under the terms and conditions of the BSD License
 | 
					  are licensed and made available under the terms and conditions of the BSD License
 | 
				
			||||||
  which accompanies this distribution.  The full text of the license may be found at
 | 
					  which accompanies this distribution.  The full text of the license may be found at
 | 
				
			||||||
@@ -39,15 +39,12 @@ GetManFileName(
 | 
				
			|||||||
  // Fix the file name
 | 
					  // Fix the file name
 | 
				
			||||||
  //
 | 
					  //
 | 
				
			||||||
  if (StrnCmp(ManFileName+StrLen(ManFileName)-4, L".man", 4)==0) {
 | 
					  if (StrnCmp(ManFileName+StrLen(ManFileName)-4, L".man", 4)==0) {
 | 
				
			||||||
    Buffer = AllocateZeroPool(StrSize(ManFileName));
 | 
					    Buffer = AllocateCopyPool(StrSize(ManFileName), ManFileName);
 | 
				
			||||||
    if (Buffer != NULL) {
 | 
					 | 
				
			||||||
      StrCpy(Buffer, ManFileName);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    Buffer = AllocateZeroPool(StrSize(ManFileName) + 4*sizeof(CHAR16));
 | 
					    Buffer = AllocateZeroPool(StrSize(ManFileName) + 4*sizeof(CHAR16));
 | 
				
			||||||
    if (Buffer != NULL) {
 | 
					    if (Buffer != NULL) {
 | 
				
			||||||
      StrCpy(Buffer, ManFileName);
 | 
					      StrnCpy(Buffer, ManFileName, StrLen(ManFileName));
 | 
				
			||||||
      StrCat(Buffer, L".man");
 | 
					      StrnCat(Buffer, L".man", 4);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return (Buffer);
 | 
					  return (Buffer);
 | 
				
			||||||
@@ -374,6 +371,9 @@ ManBufferFindTitleSection(
 | 
				
			|||||||
  CHAR16        *TitleString;
 | 
					  CHAR16        *TitleString;
 | 
				
			||||||
  CHAR16        *TitleEnd;
 | 
					  CHAR16        *TitleEnd;
 | 
				
			||||||
  CHAR16        *CurrentLocation;
 | 
					  CHAR16        *CurrentLocation;
 | 
				
			||||||
 | 
					  UINTN         TitleLength;
 | 
				
			||||||
 | 
					  CONST CHAR16  StartString[] = L".TH ";
 | 
				
			||||||
 | 
					  CONST CHAR16  EndString[]   = L" 0 ";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if ( Buffer     == NULL
 | 
					  if ( Buffer     == NULL
 | 
				
			||||||
    || Command    == NULL
 | 
					    || Command    == NULL
 | 
				
			||||||
@@ -384,13 +384,17 @@ ManBufferFindTitleSection(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  Status    = EFI_SUCCESS;
 | 
					  Status    = EFI_SUCCESS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  TitleString = AllocateZeroPool((7*sizeof(CHAR16)) + StrSize(Command));
 | 
					  //
 | 
				
			||||||
 | 
					  // more characters for StartString and EndString
 | 
				
			||||||
 | 
					  //
 | 
				
			||||||
 | 
					  TitleLength = StrSize(Command) + (StrLen(StartString) + StrLen(EndString)) * sizeof(CHAR16);
 | 
				
			||||||
 | 
					  TitleString = AllocateZeroPool(TitleLength);
 | 
				
			||||||
  if (TitleString == NULL) {
 | 
					  if (TitleString == NULL) {
 | 
				
			||||||
    return (EFI_OUT_OF_RESOURCES);
 | 
					    return (EFI_OUT_OF_RESOURCES);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  StrCpy(TitleString, L".TH ");
 | 
					  StrnCpy(TitleString, StartString, TitleLength/sizeof(CHAR16) - 1);
 | 
				
			||||||
  StrCat(TitleString, Command);
 | 
					  StrnCat(TitleString, Command,     TitleLength/sizeof(CHAR16) - 1 - StrLen(TitleString));
 | 
				
			||||||
  StrCat(TitleString, L" 0 ");
 | 
					  StrnCat(TitleString, EndString,   TitleLength/sizeof(CHAR16) - 1 - StrLen(TitleString));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  CurrentLocation = StrStr(*Buffer, TitleString);
 | 
					  CurrentLocation = StrStr(*Buffer, TitleString);
 | 
				
			||||||
  if (CurrentLocation == NULL){
 | 
					  if (CurrentLocation == NULL){
 | 
				
			||||||
@@ -467,6 +471,7 @@ ManFileFindTitleSection(
 | 
				
			|||||||
  CHAR16      *TitleEnd;
 | 
					  CHAR16      *TitleEnd;
 | 
				
			||||||
  UINTN       TitleLen;
 | 
					  UINTN       TitleLen;
 | 
				
			||||||
  BOOLEAN     Found;
 | 
					  BOOLEAN     Found;
 | 
				
			||||||
 | 
					  UINTN       TitleSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if ( Handle     == NULL
 | 
					  if ( Handle     == NULL
 | 
				
			||||||
    || Command    == NULL
 | 
					    || Command    == NULL
 | 
				
			||||||
@@ -484,13 +489,14 @@ ManFileFindTitleSection(
 | 
				
			|||||||
    return (EFI_OUT_OF_RESOURCES);
 | 
					    return (EFI_OUT_OF_RESOURCES);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  TitleString = AllocateZeroPool((4*sizeof(CHAR16)) + StrSize(Command));
 | 
					  TitleSize = (4*sizeof(CHAR16)) + StrSize(Command);
 | 
				
			||||||
 | 
					  TitleString = AllocateZeroPool(TitleSize);
 | 
				
			||||||
  if (TitleString == NULL) {
 | 
					  if (TitleString == NULL) {
 | 
				
			||||||
    FreePool(ReadLine);
 | 
					    FreePool(ReadLine);
 | 
				
			||||||
    return (EFI_OUT_OF_RESOURCES);
 | 
					    return (EFI_OUT_OF_RESOURCES);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  StrCpy(TitleString, L".TH ");
 | 
					  StrnCpy(TitleString, L".TH ", TitleSize/sizeof(CHAR16) - 1);
 | 
				
			||||||
  StrCat(TitleString, Command);
 | 
					  StrnCat(TitleString, Command, TitleSize/sizeof(CHAR16) - 1 - StrLen(TitleString));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  TitleLen = StrLen(TitleString);
 | 
					  TitleLen = StrLen(TitleString);
 | 
				
			||||||
  for (;!ShellFileHandleEof(Handle);Size = 1024) {
 | 
					  for (;!ShellFileHandleEof(Handle);Size = 1024) {
 | 
				
			||||||
@@ -526,7 +532,7 @@ ManFileFindTitleSection(
 | 
				
			|||||||
          Status = EFI_OUT_OF_RESOURCES;
 | 
					          Status = EFI_OUT_OF_RESOURCES;
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        StrCpy(*BriefDesc, TitleEnd);
 | 
					        StrnCpy(*BriefDesc, TitleEnd, (*BriefSize)/sizeof(CHAR16) - 1);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,8 +35,9 @@
 | 
				
			|||||||
VOID
 | 
					VOID
 | 
				
			||||||
EFIAPI
 | 
					EFIAPI
 | 
				
			||||||
GetNextParameter(
 | 
					GetNextParameter(
 | 
				
			||||||
  CHAR16 **Walker,
 | 
					  IN OUT CHAR16   **Walker,
 | 
				
			||||||
  CHAR16 **TempParameter
 | 
					  IN OUT CHAR16   **TempParameter,
 | 
				
			||||||
 | 
					  IN CONST UINTN  Length
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  CHAR16 *NextDelim;
 | 
					  CHAR16 *NextDelim;
 | 
				
			||||||
@@ -82,7 +83,7 @@ GetNextParameter(
 | 
				
			|||||||
      //
 | 
					      //
 | 
				
			||||||
      // found ""
 | 
					      // found ""
 | 
				
			||||||
      //
 | 
					      //
 | 
				
			||||||
      StrCpy(*TempParameter, L"");
 | 
					      *(*TempParameter) = CHAR_NULL;
 | 
				
			||||||
      *Walker = NextDelim + 1;
 | 
					      *Walker = NextDelim + 1;
 | 
				
			||||||
    } else if (NextDelim != NULL) {
 | 
					    } else if (NextDelim != NULL) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -95,7 +96,7 @@ GetNextParameter(
 | 
				
			|||||||
      //
 | 
					      //
 | 
				
			||||||
      // last one... someone forgot the training quote!
 | 
					      // last one... someone forgot the training quote!
 | 
				
			||||||
      //
 | 
					      //
 | 
				
			||||||
      StrCpy(*TempParameter, *Walker);
 | 
					      StrnCpy(*TempParameter, *Walker, Length/sizeof(CHAR16) - 1);
 | 
				
			||||||
      *Walker = NULL;
 | 
					      *Walker = NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    for (TempLoc = *TempParameter ; TempLoc != NULL && *TempLoc != CHAR_NULL ; TempLoc++) {
 | 
					    for (TempLoc = *TempParameter ; TempLoc != NULL && *TempLoc != CHAR_NULL ; TempLoc++) {
 | 
				
			||||||
@@ -117,7 +118,7 @@ GetNextParameter(
 | 
				
			|||||||
      //
 | 
					      //
 | 
				
			||||||
      // last one.
 | 
					      // last one.
 | 
				
			||||||
      //
 | 
					      //
 | 
				
			||||||
      StrCpy(*TempParameter, *Walker);
 | 
					      StrnCpy(*TempParameter, *Walker, Length/sizeof(CHAR16) - 1);
 | 
				
			||||||
      *Walker = NULL;
 | 
					      *Walker = NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    for (NextDelim = *TempParameter ; NextDelim != NULL && *NextDelim != CHAR_NULL ; NextDelim++) {
 | 
					    for (NextDelim = *TempParameter ; NextDelim != NULL && *NextDelim != CHAR_NULL ; NextDelim++) {
 | 
				
			||||||
@@ -181,17 +182,10 @@ ParseCommandLineToArgs(
 | 
				
			|||||||
  for ( Count = 0
 | 
					  for ( Count = 0
 | 
				
			||||||
      , Walker = (CHAR16*)CommandLine
 | 
					      , Walker = (CHAR16*)CommandLine
 | 
				
			||||||
      ; Walker != NULL && *Walker != CHAR_NULL
 | 
					      ; Walker != NULL && *Walker != CHAR_NULL
 | 
				
			||||||
      ; GetNextParameter(&Walker, &TempParameter)
 | 
					      ; GetNextParameter(&Walker, &TempParameter, Size)
 | 
				
			||||||
      , Count++
 | 
					      , Count++
 | 
				
			||||||
     );
 | 
					     );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*  Count = 0;
 | 
					 | 
				
			||||||
  Walker = (CHAR16*)CommandLine;
 | 
					 | 
				
			||||||
  while(Walker != NULL) {
 | 
					 | 
				
			||||||
    GetNextParameter(&Walker, &TempParameter);
 | 
					 | 
				
			||||||
    Count++;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
  //
 | 
					  //
 | 
				
			||||||
  // lets allocate the pointer array
 | 
					  // lets allocate the pointer array
 | 
				
			||||||
  //
 | 
					  //
 | 
				
			||||||
@@ -205,10 +199,12 @@ ParseCommandLineToArgs(
 | 
				
			|||||||
  Walker = (CHAR16*)CommandLine;
 | 
					  Walker = (CHAR16*)CommandLine;
 | 
				
			||||||
  while(Walker != NULL && *Walker != CHAR_NULL) {
 | 
					  while(Walker != NULL && *Walker != CHAR_NULL) {
 | 
				
			||||||
    SetMem16(TempParameter, Size, CHAR_NULL);
 | 
					    SetMem16(TempParameter, Size, CHAR_NULL);
 | 
				
			||||||
    GetNextParameter(&Walker, &TempParameter);
 | 
					    GetNextParameter(&Walker, &TempParameter, Size);
 | 
				
			||||||
    NewParam = AllocateZeroPool(StrSize(TempParameter));
 | 
					    NewParam = AllocateCopyPool(StrSize(TempParameter), TempParameter);
 | 
				
			||||||
    ASSERT(NewParam != NULL);
 | 
					    if (NewParam == NULL){
 | 
				
			||||||
    StrCpy(NewParam, TempParameter);
 | 
					      SHELL_FREE_NON_NULL(TempParameter);
 | 
				
			||||||
 | 
					      return (EFI_OUT_OF_RESOURCES);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    ((CHAR16**)(*Argv))[(*Argc)] = NewParam;
 | 
					    ((CHAR16**)(*Argv))[(*Argc)] = NewParam;
 | 
				
			||||||
    (*Argc)++;
 | 
					    (*Argc)++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -976,7 +972,7 @@ UpdateStdInStdOutStdErr(
 | 
				
			|||||||
  //
 | 
					  //
 | 
				
			||||||
  // re-populate the string to support any filenames that were in quotes.
 | 
					  // re-populate the string to support any filenames that were in quotes.
 | 
				
			||||||
  //
 | 
					  //
 | 
				
			||||||
  StrCpy(CommandLineCopy, NewCommandLine);
 | 
					  StrnCpy(CommandLineCopy, NewCommandLine, StrLen(NewCommandLine));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (FirstLocation != CommandLineCopy + StrLen(CommandLineCopy)
 | 
					  if (FirstLocation != CommandLineCopy + StrLen(CommandLineCopy)
 | 
				
			||||||
    && ((UINTN)(FirstLocation - CommandLineCopy) < StrLen(NewCommandLine))
 | 
					    && ((UINTN)(FirstLocation - CommandLineCopy) < StrLen(NewCommandLine))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -190,13 +190,15 @@ ParseCommandLineToArgs(
 | 
				
			|||||||
  @param[in, out] Walker        pointer to string of command line.  Adjusted to
 | 
					  @param[in, out] Walker        pointer to string of command line.  Adjusted to
 | 
				
			||||||
                                reminaing command line on return
 | 
					                                reminaing command line on return
 | 
				
			||||||
  @param[in, out] TempParameter pointer to string of command line item extracted.
 | 
					  @param[in, out] TempParameter pointer to string of command line item extracted.
 | 
				
			||||||
 | 
					  @param[in]      Length        Length of (*TempParameter) in bytes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
**/
 | 
					**/
 | 
				
			||||||
VOID
 | 
					VOID
 | 
				
			||||||
EFIAPI
 | 
					EFIAPI
 | 
				
			||||||
GetNextParameter(
 | 
					GetNextParameter(
 | 
				
			||||||
  CHAR16 **Walker,
 | 
					  IN OUT CHAR16   **Walker,
 | 
				
			||||||
  CHAR16 **TempParameter
 | 
					  IN OUT CHAR16   **TempParameter,
 | 
				
			||||||
 | 
					  IN CONST UINTN  Length
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif //_SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_
 | 
					#endif //_SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -530,18 +530,17 @@ EfiShellGetDevicePathFromFilePath(
 | 
				
			|||||||
    if (Cwd == NULL) {
 | 
					    if (Cwd == NULL) {
 | 
				
			||||||
      return (NULL);
 | 
					      return (NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    Size = StrSize(Cwd);
 | 
					    Size = StrSize(Cwd) + StrSize(Path) - sizeof(CHAR16);
 | 
				
			||||||
    Size += StrSize(Path);
 | 
					 | 
				
			||||||
    NewPath = AllocateZeroPool(Size);
 | 
					    NewPath = AllocateZeroPool(Size);
 | 
				
			||||||
    if (NewPath == NULL) {
 | 
					    if (NewPath == NULL) {
 | 
				
			||||||
      return (NULL);
 | 
					      return (NULL);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    StrCpy(NewPath, Cwd);
 | 
					    StrnCpy(NewPath, Cwd, Size/sizeof(CHAR16)-1);
 | 
				
			||||||
    if (*Path == L'\\') {
 | 
					    if (*Path == L'\\') {
 | 
				
			||||||
      Path++;
 | 
					      Path++;
 | 
				
			||||||
      while (PathRemoveLastItem(NewPath)) ;
 | 
					      while (PathRemoveLastItem(NewPath)) ;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    StrCat(NewPath, Path);
 | 
					    StrnCat(NewPath, Path, Size/sizeof(CHAR16) - 1 - StrLen(NewPath));
 | 
				
			||||||
    DevicePathForReturn = EfiShellGetDevicePathFromFilePath(NewPath);
 | 
					    DevicePathForReturn = EfiShellGetDevicePathFromFilePath(NewPath);
 | 
				
			||||||
    FreePool(NewPath);
 | 
					    FreePool(NewPath);
 | 
				
			||||||
    return (DevicePathForReturn);
 | 
					    return (DevicePathForReturn);
 | 
				
			||||||
@@ -1846,10 +1845,9 @@ InternalDuplicateShellFileInfo(
 | 
				
			|||||||
  if (NewNode == NULL) {
 | 
					  if (NewNode == NULL) {
 | 
				
			||||||
    return (NULL);
 | 
					    return (NULL);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  NewNode->FullName = AllocateZeroPool(StrSize(Node->FullName));
 | 
					  NewNode->FullName = AllocateCopyPool(StrSize(Node->FullName), Node->FullName);
 | 
				
			||||||
 | 
					  NewNode->FileName = AllocateCopyPool(StrSize(Node->FileName), Node->FileName);
 | 
				
			||||||
  NewNode->FileName = AllocateZeroPool(StrSize(Node->FileName));
 | 
					  NewNode->Info     = AllocateCopyPool((UINTN)Node->Info->Size, Node->Info);
 | 
				
			||||||
  NewNode->Info     = AllocateZeroPool((UINTN)Node->Info->Size);
 | 
					 | 
				
			||||||
  if ( NewNode->FullName == NULL
 | 
					  if ( NewNode->FullName == NULL
 | 
				
			||||||
    || NewNode->FileName == NULL
 | 
					    || NewNode->FileName == NULL
 | 
				
			||||||
    || NewNode->Info == NULL
 | 
					    || NewNode->Info == NULL
 | 
				
			||||||
@@ -1865,9 +1863,6 @@ InternalDuplicateShellFileInfo(
 | 
				
			|||||||
  if (!Save) {
 | 
					  if (!Save) {
 | 
				
			||||||
    Node->Handle = NULL;
 | 
					    Node->Handle = NULL;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  StrCpy((CHAR16*)NewNode->FullName, Node->FullName);
 | 
					 | 
				
			||||||
  StrCpy((CHAR16*)NewNode->FileName, Node->FileName);
 | 
					 | 
				
			||||||
  CopyMem(NewNode->Info, Node->Info, (UINTN)Node->Info->Size);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return((EFI_SHELL_FILE_INFO*)NewNode);
 | 
					  return((EFI_SHELL_FILE_INFO*)NewNode);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -2313,8 +2308,8 @@ ShellSearchHandle(
 | 
				
			|||||||
            if (NewFullName == NULL) {
 | 
					            if (NewFullName == NULL) {
 | 
				
			||||||
              Status = EFI_OUT_OF_RESOURCES;
 | 
					              Status = EFI_OUT_OF_RESOURCES;
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
              StrCpy(NewFullName, MapName);
 | 
					              StrnCpy(NewFullName, MapName, Size/sizeof(CHAR16)-1);
 | 
				
			||||||
              StrCat(NewFullName, ShellInfoNode->FullName+1);
 | 
					              StrnCat(NewFullName, ShellInfoNode->FullName+1, (Size/sizeof(CHAR16))-StrLen(NewFullName)-1);
 | 
				
			||||||
              FreePool((VOID*)ShellInfoNode->FullName);
 | 
					              FreePool((VOID*)ShellInfoNode->FullName);
 | 
				
			||||||
              ShellInfoNode->FullName = NewFullName;
 | 
					              ShellInfoNode->FullName = NewFullName;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -2437,11 +2432,10 @@ EfiShellFindFiles(
 | 
				
			|||||||
  RootDevicePath = NULL;
 | 
					  RootDevicePath = NULL;
 | 
				
			||||||
  RootFileHandle = NULL;
 | 
					  RootFileHandle = NULL;
 | 
				
			||||||
  MapName        = NULL;
 | 
					  MapName        = NULL;
 | 
				
			||||||
  PatternCopy = AllocateZeroPool(StrSize(FilePattern));
 | 
					  PatternCopy = AllocateCopyPool(StrSize(FilePattern), FilePattern);
 | 
				
			||||||
  if (PatternCopy == NULL) {
 | 
					  if (PatternCopy == NULL) {
 | 
				
			||||||
    return (EFI_OUT_OF_RESOURCES);
 | 
					    return (EFI_OUT_OF_RESOURCES);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  StrCpy(PatternCopy, FilePattern);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  PatternCopy = PathCleanUpDirectories(PatternCopy);
 | 
					  PatternCopy = PathCleanUpDirectories(PatternCopy);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2645,7 +2639,7 @@ EfiShellGetEnvEx(
 | 
				
			|||||||
      ; Node = (ENV_VAR_LIST*)GetNextNode(&List, &Node->Link)
 | 
					      ; Node = (ENV_VAR_LIST*)GetNextNode(&List, &Node->Link)
 | 
				
			||||||
     ){
 | 
					     ){
 | 
				
			||||||
      ASSERT(Node->Key != NULL);
 | 
					      ASSERT(Node->Key != NULL);
 | 
				
			||||||
      StrCpy(CurrentWriteLocation, Node->Key);
 | 
					      StrnCpy(CurrentWriteLocation, Node->Key,  (Size)/sizeof(CHAR16) - (CurrentWriteLocation - ((CHAR16*)Buffer)) - 1);
 | 
				
			||||||
      CurrentWriteLocation += StrLen(CurrentWriteLocation) + 1;
 | 
					      CurrentWriteLocation += StrLen(CurrentWriteLocation) + 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2669,7 +2663,6 @@ EfiShellGetEnvEx(
 | 
				
			|||||||
      // Allocate the space and recall the get function
 | 
					      // Allocate the space and recall the get function
 | 
				
			||||||
      //
 | 
					      //
 | 
				
			||||||
      Buffer = AllocateZeroPool(Size);
 | 
					      Buffer = AllocateZeroPool(Size);
 | 
				
			||||||
      ASSERT(Buffer != NULL);
 | 
					 | 
				
			||||||
      Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(Name, Attributes, &Size, Buffer);
 | 
					      Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(Name, Attributes, &Size, Buffer);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    //
 | 
					    //
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user