2010-09-14 07:18:09 +02:00
|
|
|
/** @file
|
|
|
|
Member functions of EFI_SHELL_PARAMETERS_PROTOCOL and functions for creation,
|
|
|
|
manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL.
|
|
|
|
|
2016-09-22 21:12:47 +02:00
|
|
|
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
|
2014-07-31 17:44:30 +02:00
|
|
|
Copyright (C) 2014, Red Hat, Inc.
|
2015-02-04 23:25:01 +01:00
|
|
|
(C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>
|
2018-06-27 15:13:38 +02:00
|
|
|
Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
|
2010-09-14 07:18:09 +02:00
|
|
|
This program and the accompanying materials
|
|
|
|
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
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
2012-11-13 23:39:09 +01:00
|
|
|
#include "Shell.h"
|
2010-09-14 07:18:09 +02:00
|
|
|
|
2015-10-15 04:43:31 +02:00
|
|
|
BOOLEAN AsciiRedirection = FALSE;
|
|
|
|
|
2016-08-23 04:40:55 +02:00
|
|
|
/**
|
|
|
|
Return the next parameter's end from a command line string.
|
|
|
|
|
|
|
|
@param[in] String the string to parse
|
|
|
|
**/
|
|
|
|
CONST CHAR16*
|
|
|
|
FindEndOfParameter(
|
|
|
|
IN CONST CHAR16 *String
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CONST CHAR16 *First;
|
|
|
|
CONST CHAR16 *CloseQuote;
|
|
|
|
|
|
|
|
First = FindFirstCharacter(String, L" \"", L'^');
|
|
|
|
|
|
|
|
//
|
|
|
|
// nothing, all one parameter remaining
|
|
|
|
//
|
|
|
|
if (*First == CHAR_NULL) {
|
|
|
|
return (First);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// If space before a quote (or neither found, i.e. both CHAR_NULL),
|
|
|
|
// then that's the end.
|
|
|
|
//
|
|
|
|
if (*First == L' ') {
|
|
|
|
return (First);
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseQuote = FindFirstCharacter (First+1, L"\"", L'^');
|
|
|
|
|
|
|
|
//
|
|
|
|
// We did not find a terminator...
|
|
|
|
//
|
|
|
|
if (*CloseQuote == CHAR_NULL) {
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (FindEndOfParameter (CloseQuote+1));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Return the next parameter from a command line string.
|
|
|
|
|
|
|
|
This function moves the next parameter from Walker into TempParameter and moves
|
|
|
|
Walker up past that parameter for recursive calling. When the final parameter
|
|
|
|
is moved *Walker will be set to NULL;
|
|
|
|
|
|
|
|
Temp Parameter must be large enough to hold the parameter before calling this
|
|
|
|
function.
|
|
|
|
|
|
|
|
This will also remove all remaining ^ characters after processing.
|
|
|
|
|
|
|
|
@param[in, out] Walker pointer to string of command line. Adjusted to
|
|
|
|
reminaing command line on return
|
|
|
|
@param[in, out] TempParameter pointer to string of command line item extracted.
|
|
|
|
@param[in] Length buffer size of TempParameter.
|
|
|
|
@param[in] StripQuotation if TRUE then strip the quotation marks surrounding
|
|
|
|
the parameters.
|
|
|
|
|
|
|
|
@return EFI_INALID_PARAMETER A required parameter was NULL or pointed to a NULL or empty string.
|
|
|
|
@return EFI_NOT_FOUND A closing " could not be found on the specified string
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
GetNextParameter(
|
|
|
|
IN OUT CHAR16 **Walker,
|
|
|
|
IN OUT CHAR16 **TempParameter,
|
|
|
|
IN CONST UINTN Length,
|
|
|
|
IN BOOLEAN StripQuotation
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CONST CHAR16 *NextDelim;
|
|
|
|
|
|
|
|
if (Walker == NULL
|
|
|
|
||*Walker == NULL
|
|
|
|
||TempParameter == NULL
|
|
|
|
||*TempParameter == NULL
|
|
|
|
){
|
|
|
|
return (EFI_INVALID_PARAMETER);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// make sure we dont have any leading spaces
|
|
|
|
//
|
|
|
|
while ((*Walker)[0] == L' ') {
|
|
|
|
(*Walker)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// make sure we still have some params now...
|
|
|
|
//
|
|
|
|
if (StrLen(*Walker) == 0) {
|
|
|
|
DEBUG_CODE_BEGIN();
|
|
|
|
*Walker = NULL;
|
|
|
|
DEBUG_CODE_END();
|
|
|
|
return (EFI_INVALID_PARAMETER);
|
|
|
|
}
|
|
|
|
|
|
|
|
NextDelim = FindEndOfParameter(*Walker);
|
|
|
|
|
|
|
|
if (NextDelim == NULL){
|
|
|
|
DEBUG_CODE_BEGIN();
|
|
|
|
*Walker = NULL;
|
|
|
|
DEBUG_CODE_END();
|
|
|
|
return (EFI_NOT_FOUND);
|
|
|
|
}
|
|
|
|
|
|
|
|
StrnCpyS(*TempParameter, Length / sizeof(CHAR16), (*Walker), NextDelim - *Walker);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Add a CHAR_NULL if we didnt get one via the copy
|
|
|
|
//
|
|
|
|
if (*NextDelim != CHAR_NULL) {
|
|
|
|
(*TempParameter)[NextDelim - *Walker] = CHAR_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Update Walker for the next iteration through the function
|
|
|
|
//
|
|
|
|
*Walker = (CHAR16*)NextDelim;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Remove any non-escaped quotes in the string
|
|
|
|
// Remove any remaining escape characters in the string
|
|
|
|
//
|
2018-06-27 15:13:38 +02:00
|
|
|
for (NextDelim = FindFirstCharacter(*TempParameter, L"\"^", CHAR_NULL)
|
|
|
|
; *NextDelim != CHAR_NULL
|
2016-08-23 04:40:55 +02:00
|
|
|
; NextDelim = FindFirstCharacter(NextDelim, L"\"^", CHAR_NULL)
|
|
|
|
) {
|
|
|
|
if (*NextDelim == L'^') {
|
|
|
|
|
|
|
|
//
|
|
|
|
// eliminate the escape ^
|
|
|
|
//
|
|
|
|
CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));
|
|
|
|
NextDelim++;
|
|
|
|
} else if (*NextDelim == L'\"') {
|
|
|
|
|
|
|
|
//
|
|
|
|
// eliminate the unescaped quote
|
|
|
|
//
|
|
|
|
if (StripQuotation) {
|
|
|
|
CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));
|
2018-06-27 15:13:38 +02:00
|
|
|
} else{
|
2016-08-23 04:40:55 +02:00
|
|
|
NextDelim++;
|
2018-06-27 15:13:38 +02:00
|
|
|
}
|
2016-08-23 04:40:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2010-09-14 07:18:09 +02:00
|
|
|
/**
|
2011-03-25 23:23:05 +01:00
|
|
|
Function to populate Argc and Argv.
|
2010-09-14 07:18:09 +02:00
|
|
|
|
|
|
|
This function parses the CommandLine and divides it into standard C style Argc/Argv
|
|
|
|
parameters for inclusion in EFI_SHELL_PARAMETERS_PROTOCOL. this supports space
|
|
|
|
delimited and quote surrounded parameter definition.
|
|
|
|
|
2018-06-27 15:13:38 +02:00
|
|
|
All special character processing (alias, environment variable, redirection,
|
2015-01-27 19:56:36 +01:00
|
|
|
etc... must be complete before calling this API.
|
|
|
|
|
2015-11-09 03:29:31 +01:00
|
|
|
@param[in] CommandLine String of command line to parse
|
|
|
|
@param[in] StripQuotation if TRUE then strip the quotation marks surrounding
|
|
|
|
the parameters.
|
|
|
|
@param[in, out] Argv pointer to array of strings; one for each parameter
|
|
|
|
@param[in, out] Argc pointer to number of strings in Argv array
|
2010-09-14 07:18:09 +02:00
|
|
|
|
|
|
|
@return EFI_SUCCESS the operation was sucessful
|
|
|
|
@return EFI_OUT_OF_RESOURCES a memory allocation failed.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
ParseCommandLineToArgs(
|
|
|
|
IN CONST CHAR16 *CommandLine,
|
2015-11-09 03:29:31 +01:00
|
|
|
IN BOOLEAN StripQuotation,
|
|
|
|
IN OUT CHAR16 ***Argv,
|
|
|
|
IN OUT UINTN *Argc
|
2010-09-14 07:18:09 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN Count;
|
|
|
|
CHAR16 *TempParameter;
|
|
|
|
CHAR16 *Walker;
|
|
|
|
CHAR16 *NewParam;
|
2015-09-18 03:08:31 +02:00
|
|
|
CHAR16 *NewCommandLine;
|
2010-09-14 07:18:09 +02:00
|
|
|
UINTN Size;
|
2015-09-18 03:08:31 +02:00
|
|
|
EFI_STATUS Status;
|
2010-09-14 07:18:09 +02:00
|
|
|
|
|
|
|
ASSERT(Argc != NULL);
|
|
|
|
ASSERT(Argv != NULL);
|
|
|
|
|
|
|
|
if (CommandLine == NULL || StrLen(CommandLine)==0) {
|
|
|
|
(*Argc) = 0;
|
|
|
|
(*Argv) = NULL;
|
|
|
|
return (EFI_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2015-09-18 03:08:31 +02:00
|
|
|
NewCommandLine = AllocateCopyPool(StrSize(CommandLine), CommandLine);
|
|
|
|
if (NewCommandLine == NULL){
|
|
|
|
return (EFI_OUT_OF_RESOURCES);
|
|
|
|
}
|
|
|
|
|
|
|
|
TrimSpaces(&NewCommandLine);
|
|
|
|
Size = StrSize(NewCommandLine);
|
2010-09-14 07:18:09 +02:00
|
|
|
TempParameter = AllocateZeroPool(Size);
|
|
|
|
if (TempParameter == NULL) {
|
2015-09-18 03:08:31 +02:00
|
|
|
SHELL_FREE_NON_NULL(NewCommandLine);
|
2010-09-14 07:18:09 +02:00
|
|
|
return (EFI_OUT_OF_RESOURCES);
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( Count = 0
|
2015-09-18 03:08:31 +02:00
|
|
|
, Walker = (CHAR16*)NewCommandLine
|
2010-09-14 07:18:09 +02:00
|
|
|
; Walker != NULL && *Walker != CHAR_NULL
|
2015-01-27 19:56:36 +01:00
|
|
|
; Count++
|
|
|
|
) {
|
2016-08-23 04:40:55 +02:00
|
|
|
if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size, TRUE))) {
|
2015-01-27 19:56:36 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// lets allocate the pointer array
|
|
|
|
//
|
|
|
|
(*Argv) = AllocateZeroPool((Count)*sizeof(CHAR16*));
|
|
|
|
if (*Argv == NULL) {
|
2015-09-18 03:08:31 +02:00
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto Done;
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*Argc = 0;
|
2015-09-18 03:08:31 +02:00
|
|
|
Walker = (CHAR16*)NewCommandLine;
|
2010-09-14 07:18:09 +02:00
|
|
|
while(Walker != NULL && *Walker != CHAR_NULL) {
|
|
|
|
SetMem16(TempParameter, Size, CHAR_NULL);
|
2016-08-23 04:40:55 +02:00
|
|
|
if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size, StripQuotation))) {
|
2015-09-18 03:08:31 +02:00
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
goto Done;
|
2015-01-27 19:56:36 +01:00
|
|
|
}
|
|
|
|
|
2014-09-02 22:17:38 +02:00
|
|
|
NewParam = AllocateCopyPool(StrSize(TempParameter), TempParameter);
|
|
|
|
if (NewParam == NULL){
|
2015-09-18 03:08:31 +02:00
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto Done;
|
2014-09-02 22:17:38 +02:00
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
((CHAR16**)(*Argv))[(*Argc)] = NewParam;
|
|
|
|
(*Argc)++;
|
|
|
|
}
|
|
|
|
ASSERT(Count >= (*Argc));
|
2015-09-18 03:08:31 +02:00
|
|
|
Status = EFI_SUCCESS;
|
2018-06-27 15:13:38 +02:00
|
|
|
|
2015-09-18 03:08:31 +02:00
|
|
|
Done:
|
2012-11-13 17:08:52 +01:00
|
|
|
SHELL_FREE_NON_NULL(TempParameter);
|
2015-09-18 03:08:31 +02:00
|
|
|
SHELL_FREE_NON_NULL(NewCommandLine);
|
|
|
|
return (Status);
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
creates a new EFI_SHELL_PARAMETERS_PROTOCOL instance and populates it and then
|
|
|
|
installs it on our handle and if there is an existing version of the protocol
|
|
|
|
that one is cached for removal later.
|
|
|
|
|
2011-09-02 10:05:34 +02:00
|
|
|
@param[in, out] NewShellParameters on a successful return, a pointer to pointer
|
2010-09-14 07:18:09 +02:00
|
|
|
to the newly installed interface.
|
2011-09-02 10:05:34 +02:00
|
|
|
@param[in, out] RootShellInstance on a successful return, pointer to boolean.
|
2010-09-14 07:18:09 +02:00
|
|
|
TRUE if this is the root shell instance.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS the operation completed successfully.
|
|
|
|
@return other the operation failed.
|
|
|
|
@sa ReinstallProtocolInterface
|
|
|
|
@sa InstallProtocolInterface
|
|
|
|
@sa ParseCommandLineToArgs
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
CreatePopulateInstallShellParametersProtocol (
|
|
|
|
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL **NewShellParameters,
|
|
|
|
IN OUT BOOLEAN *RootShellInstance
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
|
|
|
|
CHAR16 *FullCommandLine;
|
|
|
|
UINTN Size;
|
|
|
|
|
|
|
|
Size = 0;
|
|
|
|
FullCommandLine = NULL;
|
|
|
|
LoadedImage = NULL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Assert for valid parameters
|
|
|
|
//
|
|
|
|
ASSERT(NewShellParameters != NULL);
|
|
|
|
ASSERT(RootShellInstance != NULL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// See if we have a shell parameters placed on us
|
|
|
|
//
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
gImageHandle,
|
|
|
|
&gEfiShellParametersProtocolGuid,
|
|
|
|
(VOID **) &ShellInfoObject.OldShellParameters,
|
|
|
|
gImageHandle,
|
|
|
|
NULL,
|
|
|
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
|
|
|
);
|
|
|
|
//
|
|
|
|
// if we don't then we must be the root shell (error is expected)
|
|
|
|
//
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
*RootShellInstance = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate the new structure
|
|
|
|
//
|
|
|
|
*NewShellParameters = AllocateZeroPool(sizeof(EFI_SHELL_PARAMETERS_PROTOCOL));
|
2010-10-04 18:24:30 +02:00
|
|
|
if ((*NewShellParameters) == NULL) {
|
|
|
|
return (EFI_OUT_OF_RESOURCES);
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// get loaded image protocol
|
|
|
|
//
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
gImageHandle,
|
|
|
|
&gEfiLoadedImageProtocolGuid,
|
|
|
|
(VOID **) &LoadedImage,
|
|
|
|
gImageHandle,
|
|
|
|
NULL,
|
|
|
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
//
|
|
|
|
// Build the full command line
|
|
|
|
//
|
2013-01-17 20:04:36 +01:00
|
|
|
Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, FullCommandLine);
|
2010-09-14 07:18:09 +02:00
|
|
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
|
|
|
FullCommandLine = AllocateZeroPool(Size + LoadedImage->LoadOptionsSize);
|
2013-01-17 20:04:36 +01:00
|
|
|
Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, FullCommandLine);
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
if (Status == EFI_NOT_FOUND) {
|
|
|
|
//
|
|
|
|
// no parameters via environment... ok
|
|
|
|
//
|
|
|
|
} else {
|
2010-10-04 18:24:30 +02:00
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
return (Status);
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
if (Size == 0 && LoadedImage->LoadOptionsSize != 0) {
|
2010-10-04 18:24:30 +02:00
|
|
|
ASSERT(FullCommandLine == NULL);
|
2010-09-14 07:18:09 +02:00
|
|
|
//
|
|
|
|
// Now we need to include a NULL terminator in the size.
|
|
|
|
//
|
|
|
|
Size = LoadedImage->LoadOptionsSize + sizeof(FullCommandLine[0]);
|
|
|
|
FullCommandLine = AllocateZeroPool(Size);
|
|
|
|
}
|
|
|
|
if (FullCommandLine != NULL) {
|
2013-10-22 03:14:54 +02:00
|
|
|
CopyMem (FullCommandLine, LoadedImage->LoadOptions, LoadedImage->LoadOptionsSize);
|
2010-09-14 07:18:09 +02:00
|
|
|
//
|
|
|
|
// Populate Argc and Argv
|
|
|
|
//
|
|
|
|
Status = ParseCommandLineToArgs(FullCommandLine,
|
2015-11-09 03:29:31 +01:00
|
|
|
TRUE,
|
2010-09-14 07:18:09 +02:00
|
|
|
&(*NewShellParameters)->Argv,
|
|
|
|
&(*NewShellParameters)->Argc);
|
|
|
|
|
|
|
|
FreePool(FullCommandLine);
|
|
|
|
|
|
|
|
ASSERT_EFI_ERROR(Status);
|
|
|
|
} else {
|
|
|
|
(*NewShellParameters)->Argv = NULL;
|
|
|
|
(*NewShellParameters)->Argc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Populate the 3 faked file systems...
|
|
|
|
//
|
|
|
|
if (*RootShellInstance) {
|
|
|
|
(*NewShellParameters)->StdIn = &FileInterfaceStdIn;
|
|
|
|
(*NewShellParameters)->StdOut = &FileInterfaceStdOut;
|
|
|
|
(*NewShellParameters)->StdErr = &FileInterfaceStdErr;
|
|
|
|
Status = gBS->InstallProtocolInterface(&gImageHandle,
|
|
|
|
&gEfiShellParametersProtocolGuid,
|
|
|
|
EFI_NATIVE_INTERFACE,
|
|
|
|
(VOID*)(*NewShellParameters));
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// copy from the existing ones
|
|
|
|
//
|
|
|
|
(*NewShellParameters)->StdIn = ShellInfoObject.OldShellParameters->StdIn;
|
|
|
|
(*NewShellParameters)->StdOut = ShellInfoObject.OldShellParameters->StdOut;
|
|
|
|
(*NewShellParameters)->StdErr = ShellInfoObject.OldShellParameters->StdErr;
|
|
|
|
Status = gBS->ReinstallProtocolInterface(gImageHandle,
|
|
|
|
&gEfiShellParametersProtocolGuid,
|
|
|
|
(VOID*)ShellInfoObject.OldShellParameters,
|
|
|
|
(VOID*)(*NewShellParameters));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
frees all memory used by createion and installation of shell parameters protocol
|
|
|
|
and if there was an old version installed it will restore that one.
|
|
|
|
|
|
|
|
@param NewShellParameters the interface of EFI_SHELL_PARAMETERS_PROTOCOL that is
|
|
|
|
being cleaned up.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS the cleanup was successful
|
|
|
|
@return other the cleanup failed
|
|
|
|
@sa ReinstallProtocolInterface
|
|
|
|
@sa UninstallProtocolInterface
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
CleanUpShellParametersProtocol (
|
|
|
|
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *NewShellParameters
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN LoopCounter;
|
|
|
|
|
|
|
|
//
|
|
|
|
// If the old exists we need to restore it
|
|
|
|
//
|
|
|
|
if (ShellInfoObject.OldShellParameters != NULL) {
|
|
|
|
Status = gBS->ReinstallProtocolInterface(gImageHandle,
|
|
|
|
&gEfiShellParametersProtocolGuid,
|
|
|
|
(VOID*)NewShellParameters,
|
|
|
|
(VOID*)ShellInfoObject.OldShellParameters);
|
|
|
|
DEBUG_CODE(ShellInfoObject.OldShellParameters = NULL;);
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// No old one, just uninstall us...
|
|
|
|
//
|
|
|
|
Status = gBS->UninstallProtocolInterface(gImageHandle,
|
|
|
|
&gEfiShellParametersProtocolGuid,
|
|
|
|
(VOID*)NewShellParameters);
|
|
|
|
}
|
|
|
|
if (NewShellParameters->Argv != NULL) {
|
|
|
|
for ( LoopCounter = 0
|
|
|
|
; LoopCounter < NewShellParameters->Argc
|
|
|
|
; LoopCounter++
|
|
|
|
){
|
|
|
|
FreePool(NewShellParameters->Argv[LoopCounter]);
|
|
|
|
}
|
|
|
|
FreePool(NewShellParameters->Argv);
|
|
|
|
}
|
|
|
|
FreePool(NewShellParameters);
|
|
|
|
return (Status);
|
|
|
|
}
|
|
|
|
|
2011-04-02 00:16:01 +02:00
|
|
|
/**
|
|
|
|
Determin if a file name represents a unicode file.
|
|
|
|
|
|
|
|
@param[in] FileName Pointer to the filename to open.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The file is a unicode file.
|
|
|
|
@return An error upon failure.
|
|
|
|
**/
|
2011-03-25 23:23:05 +01:00
|
|
|
EFI_STATUS
|
|
|
|
IsUnicodeFile(
|
|
|
|
IN CONST CHAR16 *FileName
|
|
|
|
)
|
|
|
|
{
|
|
|
|
SHELL_FILE_HANDLE Handle;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT64 OriginalFilePosition;
|
|
|
|
UINTN CharSize;
|
|
|
|
CHAR16 CharBuffer;
|
|
|
|
|
|
|
|
Status = gEfiShellProtocol->OpenFileByName(FileName, &Handle, EFI_FILE_MODE_READ);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
return (Status);
|
|
|
|
}
|
|
|
|
gEfiShellProtocol->GetFilePosition(Handle, &OriginalFilePosition);
|
|
|
|
gEfiShellProtocol->SetFilePosition(Handle, 0);
|
|
|
|
CharSize = sizeof(CHAR16);
|
|
|
|
Status = gEfiShellProtocol->ReadFile(Handle, &CharSize, &CharBuffer);
|
|
|
|
if (EFI_ERROR(Status) || CharBuffer != gUnicodeFileTag) {
|
|
|
|
Status = EFI_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);
|
|
|
|
gEfiShellProtocol->CloseFile(Handle);
|
2018-06-27 15:13:38 +02:00
|
|
|
return (Status);
|
2011-03-25 23:23:05 +01:00
|
|
|
}
|
|
|
|
|
2011-03-30 23:04:57 +02:00
|
|
|
/**
|
|
|
|
Strips out quotes sections of a string.
|
|
|
|
|
|
|
|
All of the characters between quotes is replaced with spaces.
|
2011-04-05 22:55:45 +02:00
|
|
|
|
2011-09-02 10:05:34 +02:00
|
|
|
@param[in, out] TheString A pointer to the string to update.
|
2011-03-30 23:04:57 +02:00
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
StripQuotes (
|
|
|
|
IN OUT CHAR16 *TheString
|
|
|
|
)
|
|
|
|
{
|
|
|
|
BOOLEAN RemoveNow;
|
|
|
|
|
|
|
|
for (RemoveNow = FALSE ; TheString != NULL && *TheString != CHAR_NULL ; TheString++) {
|
|
|
|
if (*TheString == L'^' && *(TheString + 1) == L'\"') {
|
|
|
|
TheString++;
|
|
|
|
} else if (*TheString == L'\"') {
|
|
|
|
RemoveNow = (BOOLEAN)!RemoveNow;
|
|
|
|
} else if (RemoveNow) {
|
|
|
|
*TheString = L' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-14 01:05:08 +02:00
|
|
|
/**
|
|
|
|
Calcualte the 32-bit CRC in a EFI table using the service provided by the
|
|
|
|
gRuntime service.
|
|
|
|
|
|
|
|
@param Hdr Pointer to an EFI standard header
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
CalculateEfiHdrCrc (
|
|
|
|
IN OUT EFI_TABLE_HEADER *Hdr
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 Crc;
|
|
|
|
|
|
|
|
Hdr->CRC32 = 0;
|
|
|
|
|
|
|
|
//
|
|
|
|
// If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then
|
|
|
|
// Crc will come back as zero if we set it to zero here
|
|
|
|
//
|
|
|
|
Crc = 0;
|
|
|
|
gBS->CalculateCrc32 ((UINT8 *)Hdr, Hdr->HeaderSize, &Crc);
|
|
|
|
Hdr->CRC32 = Crc;
|
|
|
|
}
|
|
|
|
|
2011-11-11 17:52:09 +01:00
|
|
|
/**
|
|
|
|
Fix a string to only have the file name, removing starting at the first space of whatever is quoted.
|
|
|
|
|
|
|
|
@param[in] FileName The filename to start with.
|
|
|
|
|
|
|
|
@retval NULL FileName was invalid.
|
|
|
|
@return The modified FileName.
|
|
|
|
**/
|
|
|
|
CHAR16*
|
|
|
|
FixFileName (
|
|
|
|
IN CHAR16 *FileName
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CHAR16 *Copy;
|
|
|
|
CHAR16 *TempLocation;
|
|
|
|
|
|
|
|
if (FileName == NULL) {
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FileName[0] == L'\"') {
|
|
|
|
Copy = FileName+1;
|
|
|
|
if ((TempLocation = StrStr(Copy , L"\"")) != NULL) {
|
|
|
|
TempLocation[0] = CHAR_NULL;
|
2018-06-27 15:13:38 +02:00
|
|
|
}
|
2011-11-11 17:52:09 +01:00
|
|
|
} else {
|
|
|
|
Copy = FileName;
|
2012-01-27 21:51:14 +01:00
|
|
|
while(Copy[0] == L' ') {
|
|
|
|
Copy++;
|
|
|
|
}
|
2011-11-11 17:52:09 +01:00
|
|
|
if ((TempLocation = StrStr(Copy , L" ")) != NULL) {
|
|
|
|
TempLocation[0] = CHAR_NULL;
|
2018-06-27 15:13:38 +02:00
|
|
|
}
|
2011-11-11 17:52:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Copy[0] == CHAR_NULL) {
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (Copy);
|
|
|
|
}
|
|
|
|
|
2013-11-15 19:39:26 +01:00
|
|
|
/**
|
|
|
|
Fix a string to only have the environment variable name, removing starting at the first space of whatever is quoted and removing the leading and trailing %.
|
|
|
|
|
|
|
|
@param[in] FileName The filename to start with.
|
|
|
|
|
|
|
|
@retval NULL FileName was invalid.
|
|
|
|
@return The modified FileName.
|
|
|
|
**/
|
|
|
|
CHAR16*
|
|
|
|
FixVarName (
|
|
|
|
IN CHAR16 *FileName
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CHAR16 *Copy;
|
|
|
|
CHAR16 *TempLocation;
|
|
|
|
|
|
|
|
Copy = FileName;
|
|
|
|
|
|
|
|
if (FileName[0] == L'%') {
|
|
|
|
Copy = FileName+1;
|
|
|
|
if ((TempLocation = StrStr(Copy , L"%")) != NULL) {
|
|
|
|
TempLocation[0] = CHAR_NULL;
|
2018-06-27 15:13:38 +02:00
|
|
|
}
|
2013-11-15 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (FixFileName(Copy));
|
|
|
|
}
|
|
|
|
|
2014-01-13 19:52:48 +01:00
|
|
|
/**
|
|
|
|
Remove the unicode file tag from the begining of the file buffer since that will not be
|
|
|
|
used by StdIn.
|
2018-06-27 15:13:38 +02:00
|
|
|
|
2014-01-23 01:27:52 +01:00
|
|
|
@param[in] Handle Pointer to the handle of the file to be processed.
|
2018-06-27 15:13:38 +02:00
|
|
|
|
2014-01-23 01:27:52 +01:00
|
|
|
@retval EFI_SUCCESS The unicode file tag has been moved successfully.
|
2014-01-13 19:52:48 +01:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
RemoveFileTag(
|
|
|
|
IN SHELL_FILE_HANDLE *Handle
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN CharSize;
|
|
|
|
CHAR16 CharBuffer;
|
|
|
|
|
|
|
|
CharSize = sizeof(CHAR16);
|
|
|
|
CharBuffer = 0;
|
|
|
|
gEfiShellProtocol->ReadFile(*Handle, &CharSize, &CharBuffer);
|
|
|
|
if (CharBuffer != gUnicodeFileTag) {
|
|
|
|
gEfiShellProtocol->SetFilePosition(*Handle, 0);
|
|
|
|
}
|
|
|
|
return (EFI_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2014-07-31 17:44:30 +02:00
|
|
|
/**
|
|
|
|
Write the unicode file tag to the specified file.
|
|
|
|
|
|
|
|
It is the caller's responsibility to ensure that
|
|
|
|
ShellInfoObject.NewEfiShellProtocol has been initialized before calling this
|
|
|
|
function.
|
|
|
|
|
|
|
|
@param[in] FileHandle The file to write the unicode file tag to.
|
|
|
|
|
|
|
|
@return Status code from ShellInfoObject.NewEfiShellProtocol->WriteFile.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
WriteFileTag (
|
|
|
|
IN SHELL_FILE_HANDLE FileHandle
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CHAR16 FileTag;
|
|
|
|
UINTN Size;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
FileTag = gUnicodeFileTag;
|
|
|
|
Size = sizeof FileTag;
|
|
|
|
Status = ShellInfoObject.NewEfiShellProtocol->WriteFile (FileHandle, &Size,
|
|
|
|
&FileTag);
|
|
|
|
ASSERT (EFI_ERROR (Status) || Size == sizeof FileTag);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-14 07:18:09 +02:00
|
|
|
/**
|
|
|
|
Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
|
|
|
|
structure by parsing NewCommandLine. The current values are returned to the
|
|
|
|
user.
|
|
|
|
|
2010-11-16 23:31:47 +01:00
|
|
|
This will also update the system table.
|
2010-09-14 07:18:09 +02:00
|
|
|
|
2011-09-02 10:05:34 +02:00
|
|
|
@param[in, out] ShellParameters Pointer to parameter structure to modify.
|
|
|
|
@param[in] NewCommandLine The new command line to parse and use.
|
|
|
|
@param[out] OldStdIn Pointer to old StdIn.
|
|
|
|
@param[out] OldStdOut Pointer to old StdOut.
|
|
|
|
@param[out] OldStdErr Pointer to old StdErr.
|
|
|
|
@param[out] SystemTableInfo Pointer to old system table information.
|
2010-09-14 07:18:09 +02:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
UpdateStdInStdOutStdErr(
|
|
|
|
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
|
2011-03-30 23:04:57 +02:00
|
|
|
IN CHAR16 *NewCommandLine,
|
2010-09-14 07:18:09 +02:00
|
|
|
OUT SHELL_FILE_HANDLE *OldStdIn,
|
|
|
|
OUT SHELL_FILE_HANDLE *OldStdOut,
|
2010-11-16 23:31:47 +01:00
|
|
|
OUT SHELL_FILE_HANDLE *OldStdErr,
|
|
|
|
OUT SYSTEM_TABLE_INFO *SystemTableInfo
|
2010-09-14 07:18:09 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
CHAR16 *CommandLineCopy;
|
|
|
|
CHAR16 *CommandLineWalker;
|
|
|
|
CHAR16 *StdErrFileName;
|
|
|
|
CHAR16 *StdOutFileName;
|
|
|
|
CHAR16 *StdInFileName;
|
|
|
|
CHAR16 *StdInVarName;
|
|
|
|
CHAR16 *StdOutVarName;
|
|
|
|
CHAR16 *StdErrVarName;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
SHELL_FILE_HANDLE TempHandle;
|
|
|
|
UINT64 FileSize;
|
|
|
|
BOOLEAN OutUnicode;
|
|
|
|
BOOLEAN InUnicode;
|
|
|
|
BOOLEAN ErrUnicode;
|
|
|
|
BOOLEAN OutAppend;
|
|
|
|
BOOLEAN ErrAppend;
|
|
|
|
UINTN Size;
|
|
|
|
SPLIT_LIST *Split;
|
2011-03-30 23:04:57 +02:00
|
|
|
CHAR16 *FirstLocation;
|
2016-07-08 09:18:14 +02:00
|
|
|
BOOLEAN Volatile;
|
2010-09-14 07:18:09 +02:00
|
|
|
|
|
|
|
OutUnicode = TRUE;
|
|
|
|
InUnicode = TRUE;
|
2015-10-15 04:43:31 +02:00
|
|
|
AsciiRedirection = FALSE;
|
2010-09-14 07:18:09 +02:00
|
|
|
ErrUnicode = TRUE;
|
|
|
|
StdInVarName = NULL;
|
|
|
|
StdOutVarName = NULL;
|
|
|
|
StdErrVarName = NULL;
|
|
|
|
StdErrFileName = NULL;
|
|
|
|
StdInFileName = NULL;
|
|
|
|
StdOutFileName = NULL;
|
|
|
|
ErrAppend = FALSE;
|
|
|
|
OutAppend = FALSE;
|
|
|
|
CommandLineCopy = NULL;
|
2011-04-01 18:11:59 +02:00
|
|
|
FirstLocation = NULL;
|
2010-09-14 07:18:09 +02:00
|
|
|
|
2010-11-16 23:31:47 +01:00
|
|
|
if (ShellParameters == NULL || SystemTableInfo == NULL || OldStdIn == NULL || OldStdOut == NULL || OldStdErr == NULL) {
|
|
|
|
return (EFI_INVALID_PARAMETER);
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
|
2010-11-16 23:31:47 +01:00
|
|
|
SystemTableInfo->ConIn = gST->ConIn;
|
|
|
|
SystemTableInfo->ConInHandle = gST->ConsoleInHandle;
|
|
|
|
SystemTableInfo->ConOut = gST->ConOut;
|
|
|
|
SystemTableInfo->ConOutHandle = gST->ConsoleOutHandle;
|
2012-08-17 05:58:17 +02:00
|
|
|
SystemTableInfo->ErrOut = gST->StdErr;
|
|
|
|
SystemTableInfo->ErrOutHandle = gST->StandardErrorHandle;
|
2010-11-16 23:31:47 +01:00
|
|
|
*OldStdIn = ShellParameters->StdIn;
|
|
|
|
*OldStdOut = ShellParameters->StdOut;
|
|
|
|
*OldStdErr = ShellParameters->StdErr;
|
|
|
|
|
2010-09-14 07:18:09 +02:00
|
|
|
if (NewCommandLine == NULL) {
|
|
|
|
return (EFI_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandLineCopy = StrnCatGrow(&CommandLineCopy, NULL, NewCommandLine, 0);
|
2011-10-14 21:21:13 +02:00
|
|
|
if (CommandLineCopy == NULL) {
|
|
|
|
return (EFI_OUT_OF_RESOURCES);
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
Split = NULL;
|
2011-04-01 18:11:59 +02:00
|
|
|
FirstLocation = CommandLineCopy + StrLen(CommandLineCopy);
|
2010-09-14 07:18:09 +02:00
|
|
|
|
2011-03-30 23:04:57 +02:00
|
|
|
StripQuotes(CommandLineCopy);
|
|
|
|
|
2010-09-14 07:18:09 +02:00
|
|
|
if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) {
|
|
|
|
Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link);
|
|
|
|
if (Split != NULL && Split->SplitStdIn != NULL) {
|
|
|
|
ShellParameters->StdIn = Split->SplitStdIn;
|
|
|
|
}
|
|
|
|
if (Split != NULL && Split->SplitStdOut != NULL) {
|
|
|
|
ShellParameters->StdOut = Split->SplitStdOut;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>>v ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 12, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
StdErrVarName = CommandLineWalker += 6;
|
|
|
|
ErrAppend = TRUE;
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" 2>>v ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>>v ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 12, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
StdOutVarName = CommandLineWalker += 6;
|
|
|
|
OutAppend = TRUE;
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" 1>>v ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
} else if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >>v ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 10, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
StdOutVarName = CommandLineWalker += 5;
|
|
|
|
OutAppend = TRUE;
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" >>v ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
} else if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >v ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 8, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
StdOutVarName = CommandLineWalker += 4;
|
|
|
|
OutAppend = FALSE;
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" >v ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>>a ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 12, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
StdOutFileName = CommandLineWalker += 6;
|
|
|
|
OutAppend = TRUE;
|
|
|
|
OutUnicode = FALSE;
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" 1>>a ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>> ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 10, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
if (StdOutFileName != NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
StdOutFileName = CommandLineWalker += 5;
|
|
|
|
OutAppend = TRUE;
|
|
|
|
}
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" 1>> ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2018-06-27 15:13:38 +02:00
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >> ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 8, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
if (StdOutFileName != NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
StdOutFileName = CommandLineWalker += 4;
|
|
|
|
OutAppend = TRUE;
|
|
|
|
}
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" >> ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >>a ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 10, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
if (StdOutFileName != NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
StdOutFileName = CommandLineWalker += 5;
|
|
|
|
OutAppend = TRUE;
|
|
|
|
OutUnicode = FALSE;
|
|
|
|
}
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" >>a ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2018-06-27 15:13:38 +02:00
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>a ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 10, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
if (StdOutFileName != NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
StdOutFileName = CommandLineWalker += 5;
|
|
|
|
OutAppend = FALSE;
|
|
|
|
OutUnicode = FALSE;
|
|
|
|
}
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" 1>a ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2018-06-27 15:13:38 +02:00
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >a ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 8, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
if (StdOutFileName != NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
StdOutFileName = CommandLineWalker += 4;
|
|
|
|
OutAppend = FALSE;
|
|
|
|
OutUnicode = FALSE;
|
|
|
|
}
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" >a ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>> ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 10, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
if (StdErrFileName != NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
StdErrFileName = CommandLineWalker += 5;
|
|
|
|
ErrAppend = TRUE;
|
|
|
|
}
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" 2>> ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>v ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 10, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
if (StdErrVarName != NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
StdErrVarName = CommandLineWalker += 5;
|
|
|
|
ErrAppend = FALSE;
|
|
|
|
}
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" 2>v ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>v ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 10, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
if (StdOutVarName != NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
StdOutVarName = CommandLineWalker += 5;
|
|
|
|
OutAppend = FALSE;
|
|
|
|
}
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" 1>v ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>a ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 10, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
if (StdErrFileName != NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
StdErrFileName = CommandLineWalker += 5;
|
|
|
|
ErrAppend = FALSE;
|
|
|
|
ErrUnicode = FALSE;
|
|
|
|
}
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" 2>a ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2> ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 8, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
if (StdErrFileName != NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
StdErrFileName = CommandLineWalker += 4;
|
|
|
|
ErrAppend = FALSE;
|
|
|
|
}
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" 2> ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1> ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 8, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
if (StdOutFileName != NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
StdOutFileName = CommandLineWalker += 4;
|
|
|
|
OutAppend = FALSE;
|
|
|
|
}
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" 1> ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" > ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 6, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
if (StdOutFileName != NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
StdOutFileName = CommandLineWalker += 3;
|
|
|
|
OutAppend = FALSE;
|
|
|
|
}
|
2011-03-25 23:23:05 +01:00
|
|
|
if (StrStr(CommandLineWalker, L" > ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" < ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 6, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
if (StdInFileName != NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
StdInFileName = CommandLineWalker += 3;
|
2011-03-25 23:23:05 +01:00
|
|
|
}
|
|
|
|
if (StrStr(CommandLineWalker, L" < ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" <a ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 8, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
if (StdInFileName != NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
2011-03-25 23:23:05 +01:00
|
|
|
StdInFileName = CommandLineWalker += 4;
|
|
|
|
InUnicode = FALSE;
|
2015-10-15 04:43:31 +02:00
|
|
|
AsciiRedirection = TRUE;
|
2011-03-25 23:23:05 +01:00
|
|
|
}
|
|
|
|
if (StrStr(CommandLineWalker, L" <a ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" <v ")) != NULL) {
|
2011-03-30 23:04:57 +02:00
|
|
|
FirstLocation = MIN(CommandLineWalker, FirstLocation);
|
2011-03-25 23:23:05 +01:00
|
|
|
SetMem16(CommandLineWalker, 8, L' ');
|
2010-09-14 07:18:09 +02:00
|
|
|
if (StdInVarName != NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
StdInVarName = CommandLineWalker += 4;
|
2011-03-25 23:23:05 +01:00
|
|
|
}
|
|
|
|
if (StrStr(CommandLineWalker, L" <v ") != NULL) {
|
|
|
|
Status = EFI_NOT_FOUND;
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-11 17:52:09 +01:00
|
|
|
//
|
|
|
|
// re-populate the string to support any filenames that were in quotes.
|
|
|
|
//
|
2015-06-30 05:18:31 +02:00
|
|
|
StrnCpyS(CommandLineCopy, StrSize(CommandLineCopy)/sizeof(CHAR16), NewCommandLine, StrLen(NewCommandLine));
|
2011-11-11 17:52:09 +01:00
|
|
|
|
2011-04-01 18:11:59 +02:00
|
|
|
if (FirstLocation != CommandLineCopy + StrLen(CommandLineCopy)
|
ShellPkg: Refine type cast for pointer subtraction
For pointer subtraction, the result is of type "ptrdiff_t". According to
the C11 standard (Committee Draft - April 12, 2011):
"When two pointers are subtracted, both shall point to elements of the
same array object, or one past the last element of the array object; the
result is the difference of the subscripts of the two array elements. The
size of the result is implementation-defined, and its type (a signed
integer type) is ptrdiff_t defined in the <stddef.h> header. If the result
is not representable in an object of that type, the behavior is
undefined."
In our codes, there are cases that the pointer subtraction is not
performed by pointers to elements of the same array object. This might
lead to potential issues, since the behavior is undefined according to C11
standard.
Also, since the size of type "ptrdiff_t" is implementation-defined. Some
static code checkers may warn that the pointer subtraction might underflow
first and then being cast to a bigger size. For example:
UINT8 *Ptr1, *Ptr2;
UINTN PtrDiff;
...
PtrDiff = (UINTN) (Ptr1 - Ptr2);
The commit will refine the pointer subtraction expressions by casting each
pointer to UINTN first and then perform the subtraction:
PtrDiff = (UINTN) Ptr1 - (UINTN) Ptr2;
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
2017-01-23 07:38:43 +01:00
|
|
|
&& (((UINTN)FirstLocation - (UINTN)CommandLineCopy)/sizeof(CHAR16) < StrLen(NewCommandLine))
|
2011-03-30 23:04:57 +02:00
|
|
|
){
|
ShellPkg: Refine type cast for pointer subtraction
For pointer subtraction, the result is of type "ptrdiff_t". According to
the C11 standard (Committee Draft - April 12, 2011):
"When two pointers are subtracted, both shall point to elements of the
same array object, or one past the last element of the array object; the
result is the difference of the subscripts of the two array elements. The
size of the result is implementation-defined, and its type (a signed
integer type) is ptrdiff_t defined in the <stddef.h> header. If the result
is not representable in an object of that type, the behavior is
undefined."
In our codes, there are cases that the pointer subtraction is not
performed by pointers to elements of the same array object. This might
lead to potential issues, since the behavior is undefined according to C11
standard.
Also, since the size of type "ptrdiff_t" is implementation-defined. Some
static code checkers may warn that the pointer subtraction might underflow
first and then being cast to a bigger size. For example:
UINT8 *Ptr1, *Ptr2;
UINTN PtrDiff;
...
PtrDiff = (UINTN) (Ptr1 - Ptr2);
The commit will refine the pointer subtraction expressions by casting each
pointer to UINTN first and then perform the subtraction:
PtrDiff = (UINTN) Ptr1 - (UINTN) Ptr2;
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
2017-01-23 07:38:43 +01:00
|
|
|
*(NewCommandLine + ((UINTN)FirstLocation - (UINTN)CommandLineCopy)/sizeof(CHAR16)) = CHAR_NULL;
|
2011-03-30 23:04:57 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 07:18:09 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
2011-11-11 17:52:09 +01:00
|
|
|
|
|
|
|
if (StdErrFileName != NULL) {
|
|
|
|
if ((StdErrFileName = FixFileName(StdErrFileName)) == NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
2011-11-11 17:52:09 +01:00
|
|
|
if (StdOutFileName != NULL) {
|
|
|
|
if ((StdOutFileName = FixFileName(StdOutFileName)) == NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
2011-11-11 17:52:09 +01:00
|
|
|
if (StdInFileName != NULL) {
|
|
|
|
if ((StdInFileName = FixFileName(StdInFileName)) == NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
2011-11-11 17:52:09 +01:00
|
|
|
if (StdErrVarName != NULL) {
|
2013-11-15 19:39:26 +01:00
|
|
|
if ((StdErrVarName = FixVarName(StdErrVarName)) == NULL) {
|
2011-11-11 17:52:09 +01:00
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
2011-11-11 17:52:09 +01:00
|
|
|
if (StdOutVarName != NULL) {
|
2013-11-15 19:39:26 +01:00
|
|
|
if ((StdOutVarName = FixVarName(StdOutVarName)) == NULL) {
|
2011-11-11 17:52:09 +01:00
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
2011-11-11 17:52:09 +01:00
|
|
|
if (StdInVarName != NULL) {
|
2013-11-15 19:39:26 +01:00
|
|
|
if ((StdInVarName = FixVarName(StdInVarName)) == NULL) {
|
2011-11-11 17:52:09 +01:00
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
|
2011-03-30 23:05:25 +02:00
|
|
|
//
|
|
|
|
// Verify not the same and not duplicating something from a split
|
|
|
|
//
|
2011-03-25 23:23:05 +01:00
|
|
|
if (
|
|
|
|
//
|
|
|
|
// Check that no 2 filenames are the same
|
|
|
|
//
|
2011-03-30 23:04:57 +02:00
|
|
|
(StdErrFileName != NULL && StdOutFileName!= NULL && StringNoCaseCompare(&StdErrFileName, &StdOutFileName) == 0)
|
2010-09-14 07:18:09 +02:00
|
|
|
||(StdErrFileName != NULL && StdInFileName != NULL && StringNoCaseCompare(&StdErrFileName, &StdInFileName ) == 0)
|
|
|
|
||(StdOutFileName != NULL && StdInFileName != NULL && StringNoCaseCompare(&StdOutFileName, &StdInFileName ) == 0)
|
2011-03-25 23:23:05 +01:00
|
|
|
//
|
|
|
|
// Check that no 2 variable names are the same
|
|
|
|
//
|
2010-09-14 07:18:09 +02:00
|
|
|
||(StdErrVarName != NULL && StdInVarName != NULL && StringNoCaseCompare(&StdErrVarName , &StdInVarName ) == 0)
|
|
|
|
||(StdOutVarName != NULL && StdInVarName != NULL && StringNoCaseCompare(&StdOutVarName , &StdInVarName ) == 0)
|
|
|
|
||(StdErrVarName != NULL && StdOutVarName != NULL && StringNoCaseCompare(&StdErrVarName , &StdOutVarName ) == 0)
|
2011-03-25 23:23:05 +01:00
|
|
|
//
|
|
|
|
// When a split (using | operator) is in place some are not allowed
|
|
|
|
//
|
2010-09-14 07:18:09 +02:00
|
|
|
||(Split != NULL && Split->SplitStdIn != NULL && (StdInVarName != NULL || StdInFileName != NULL))
|
|
|
|
||(Split != NULL && Split->SplitStdOut != NULL && (StdOutVarName != NULL || StdOutFileName != NULL))
|
2011-03-25 23:23:05 +01:00
|
|
|
//
|
|
|
|
// Check that nothing is trying to be output to 2 locations.
|
|
|
|
//
|
2010-09-14 07:18:09 +02:00
|
|
|
||(StdErrFileName != NULL && StdErrVarName != NULL)
|
|
|
|
||(StdOutFileName != NULL && StdOutVarName != NULL)
|
|
|
|
||(StdInFileName != NULL && StdInVarName != NULL)
|
2011-03-25 23:23:05 +01:00
|
|
|
//
|
|
|
|
// Check for no volatile environment variables
|
|
|
|
//
|
2016-07-08 09:18:14 +02:00
|
|
|
||(StdErrVarName != NULL && !EFI_ERROR (IsVolatileEnv (StdErrVarName, &Volatile)) && !Volatile)
|
|
|
|
||(StdOutVarName != NULL && !EFI_ERROR (IsVolatileEnv (StdOutVarName, &Volatile)) && !Volatile)
|
2011-03-25 23:23:05 +01:00
|
|
|
//
|
|
|
|
// Cant redirect during a reconnect operation.
|
|
|
|
//
|
2018-06-27 15:13:38 +02:00
|
|
|
||(StrStr(NewCommandLine, L"connect -r") != NULL
|
2010-10-04 18:24:30 +02:00
|
|
|
&& (StdOutVarName != NULL || StdOutFileName != NULL || StdErrFileName != NULL || StdErrVarName != NULL))
|
2011-03-25 23:23:05 +01:00
|
|
|
//
|
|
|
|
// Check that filetypes (Unicode/Ascii) do not change during an append
|
|
|
|
//
|
|
|
|
||(StdOutFileName != NULL && OutUnicode && OutAppend && (!EFI_ERROR(ShellFileExists(StdOutFileName)) && EFI_ERROR(IsUnicodeFile(StdOutFileName))))
|
|
|
|
||(StdErrFileName != NULL && ErrUnicode && ErrAppend && (!EFI_ERROR(ShellFileExists(StdErrFileName)) && EFI_ERROR(IsUnicodeFile(StdErrFileName))))
|
|
|
|
||(StdOutFileName != NULL && !OutUnicode && OutAppend && (!EFI_ERROR(ShellFileExists(StdOutFileName)) && !EFI_ERROR(IsUnicodeFile(StdOutFileName))))
|
|
|
|
||(StdErrFileName != NULL && !ErrUnicode && ErrAppend && (!EFI_ERROR(ShellFileExists(StdErrFileName)) && !EFI_ERROR(IsUnicodeFile(StdErrFileName))))
|
2010-09-14 07:18:09 +02:00
|
|
|
){
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
2011-06-16 00:25:14 +02:00
|
|
|
ShellParameters->StdIn = *OldStdIn;
|
|
|
|
ShellParameters->StdOut = *OldStdOut;
|
|
|
|
ShellParameters->StdErr = *OldStdErr;
|
2011-03-30 23:04:57 +02:00
|
|
|
} else if (!EFI_ERROR(Status)){
|
2010-09-14 07:18:09 +02:00
|
|
|
//
|
|
|
|
// Open the Std<Whatever> and we should not have conflicts here...
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// StdErr to a file
|
|
|
|
//
|
|
|
|
if (StdErrFileName != NULL) {
|
|
|
|
if (!ErrAppend) {
|
|
|
|
//
|
|
|
|
// delete existing file.
|
|
|
|
//
|
|
|
|
ShellInfoObject.NewEfiShellProtocol->DeleteFileByName(StdErrFileName);
|
|
|
|
}
|
|
|
|
Status = ShellOpenFileByName(StdErrFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE,0);
|
|
|
|
if (!ErrAppend && ErrUnicode && !EFI_ERROR(Status)) {
|
2014-07-31 17:44:30 +02:00
|
|
|
Status = WriteFileTag (TempHandle);
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
if (!ErrUnicode && !EFI_ERROR(Status)) {
|
|
|
|
TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
|
|
|
|
ASSERT(TempHandle != NULL);
|
|
|
|
}
|
|
|
|
if (!EFI_ERROR(Status)) {
|
|
|
|
ShellParameters->StdErr = TempHandle;
|
2013-10-24 19:47:57 +02:00
|
|
|
gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle, gST->StdErr);
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// StdOut to a file
|
|
|
|
//
|
|
|
|
if (!EFI_ERROR(Status) && StdOutFileName != NULL) {
|
|
|
|
if (!OutAppend) {
|
|
|
|
//
|
|
|
|
// delete existing file.
|
|
|
|
//
|
|
|
|
ShellInfoObject.NewEfiShellProtocol->DeleteFileByName(StdOutFileName);
|
|
|
|
}
|
|
|
|
Status = ShellOpenFileByName(StdOutFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE,0);
|
2010-10-04 18:24:30 +02:00
|
|
|
if (TempHandle == NULL) {
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
2016-09-22 21:12:47 +02:00
|
|
|
if (gUnicodeCollation->MetaiMatch (gUnicodeCollation, StdOutFileName, L"NUL")) {
|
2011-03-25 23:23:05 +01:00
|
|
|
//no-op
|
|
|
|
} else if (!OutAppend && OutUnicode && !EFI_ERROR(Status)) {
|
2014-07-31 17:44:30 +02:00
|
|
|
Status = WriteFileTag (TempHandle);
|
2010-10-04 18:24:30 +02:00
|
|
|
} else if (OutAppend) {
|
|
|
|
Status = ShellInfoObject.NewEfiShellProtocol->GetFileSize(TempHandle, &FileSize);
|
|
|
|
if (!EFI_ERROR(Status)) {
|
2014-07-31 17:44:43 +02:00
|
|
|
//
|
|
|
|
// When appending to a new unicode file, write the file tag.
|
|
|
|
// Otherwise (ie. when appending to a new ASCII file, or an
|
|
|
|
// existent file with any encoding), just seek to the end.
|
|
|
|
//
|
|
|
|
Status = (FileSize == 0 && OutUnicode) ?
|
|
|
|
WriteFileTag (TempHandle) :
|
|
|
|
ShellInfoObject.NewEfiShellProtocol->SetFilePosition (
|
|
|
|
TempHandle,
|
|
|
|
FileSize);
|
2010-10-04 18:24:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!OutUnicode && !EFI_ERROR(Status)) {
|
|
|
|
TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
|
|
|
|
ASSERT(TempHandle != NULL);
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
if (!EFI_ERROR(Status)) {
|
2010-10-04 18:24:30 +02:00
|
|
|
ShellParameters->StdOut = TempHandle;
|
2013-10-24 19:47:57 +02:00
|
|
|
gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle, gST->ConOut);
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// StdOut to a var
|
|
|
|
//
|
|
|
|
if (!EFI_ERROR(Status) && StdOutVarName != NULL) {
|
|
|
|
if (!OutAppend) {
|
|
|
|
//
|
|
|
|
// delete existing variable.
|
|
|
|
//
|
|
|
|
SHELL_SET_ENVIRONMENT_VARIABLE_V(StdOutVarName, 0, L"");
|
|
|
|
}
|
|
|
|
TempHandle = CreateFileInterfaceEnv(StdOutVarName);
|
|
|
|
ASSERT(TempHandle != NULL);
|
|
|
|
ShellParameters->StdOut = TempHandle;
|
2013-10-24 19:47:57 +02:00
|
|
|
gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle, gST->ConOut);
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// StdErr to a var
|
|
|
|
//
|
|
|
|
if (!EFI_ERROR(Status) && StdErrVarName != NULL) {
|
|
|
|
if (!ErrAppend) {
|
|
|
|
//
|
|
|
|
// delete existing variable.
|
|
|
|
//
|
|
|
|
SHELL_SET_ENVIRONMENT_VARIABLE_V(StdErrVarName, 0, L"");
|
|
|
|
}
|
|
|
|
TempHandle = CreateFileInterfaceEnv(StdErrVarName);
|
|
|
|
ASSERT(TempHandle != NULL);
|
|
|
|
ShellParameters->StdErr = TempHandle;
|
2013-10-24 19:47:57 +02:00
|
|
|
gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle, gST->StdErr);
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// StdIn from a var
|
|
|
|
//
|
|
|
|
if (!EFI_ERROR(Status) && StdInVarName != NULL) {
|
|
|
|
TempHandle = CreateFileInterfaceEnv(StdInVarName);
|
2011-10-14 21:21:13 +02:00
|
|
|
if (TempHandle == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
2010-09-14 07:18:09 +02:00
|
|
|
} else {
|
2011-10-14 21:21:13 +02:00
|
|
|
if (!InUnicode) {
|
|
|
|
TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
|
|
|
|
}
|
|
|
|
Size = 0;
|
2011-10-22 06:10:30 +02:00
|
|
|
if (TempHandle == NULL || ((EFI_FILE_PROTOCOL*)TempHandle)->Read(TempHandle, &Size, NULL) != EFI_BUFFER_TOO_SMALL) {
|
2011-10-14 21:21:13 +02:00
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
} else {
|
|
|
|
ShellParameters->StdIn = TempHandle;
|
|
|
|
gST->ConIn = CreateSimpleTextInOnFile(TempHandle, &gST->ConsoleInHandle);
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// StdIn from a file
|
|
|
|
//
|
|
|
|
if (!EFI_ERROR(Status) && StdInFileName != NULL) {
|
|
|
|
Status = ShellOpenFileByName(
|
|
|
|
StdInFileName,
|
|
|
|
&TempHandle,
|
|
|
|
EFI_FILE_MODE_READ,
|
|
|
|
0);
|
|
|
|
if (!EFI_ERROR(Status)) {
|
2016-03-08 13:51:43 +01:00
|
|
|
if (!InUnicode) {
|
|
|
|
//
|
|
|
|
// Create the ASCII->Unicode conversion layer
|
|
|
|
//
|
|
|
|
TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
ShellParameters->StdIn = TempHandle;
|
2010-11-16 23:31:47 +01:00
|
|
|
gST->ConIn = CreateSimpleTextInOnFile(TempHandle, &gST->ConsoleInHandle);
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FreePool(CommandLineCopy);
|
2010-11-16 23:31:47 +01:00
|
|
|
|
2011-10-14 01:05:08 +02:00
|
|
|
CalculateEfiHdrCrc(&gST->Hdr);
|
|
|
|
|
2010-11-16 23:31:47 +01:00
|
|
|
if (gST->ConIn == NULL ||gST->ConOut == NULL) {
|
2013-12-14 00:53:59 +01:00
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
2010-11-16 23:31:47 +01:00
|
|
|
}
|
2013-12-14 00:53:59 +01:00
|
|
|
|
|
|
|
if (Status == EFI_NOT_FOUND) {
|
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR), ShellInfoObject.HiiHandle);
|
|
|
|
} else if (EFI_ERROR(Status)) {
|
|
|
|
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle);
|
|
|
|
}
|
|
|
|
|
2010-09-14 07:18:09 +02:00
|
|
|
return (Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
|
|
|
|
structure with StdIn and StdOut. The current values are de-allocated.
|
|
|
|
|
2011-09-02 10:05:34 +02:00
|
|
|
@param[in, out] ShellParameters Pointer to parameter structure to modify.
|
|
|
|
@param[in] OldStdIn Pointer to old StdIn.
|
|
|
|
@param[in] OldStdOut Pointer to old StdOut.
|
|
|
|
@param[in] OldStdErr Pointer to old StdErr.
|
|
|
|
@param[in] SystemTableInfo Pointer to old system table information.
|
2010-09-14 07:18:09 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
RestoreStdInStdOutStdErr (
|
|
|
|
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
|
2010-11-16 23:31:47 +01:00
|
|
|
IN SHELL_FILE_HANDLE *OldStdIn,
|
|
|
|
IN SHELL_FILE_HANDLE *OldStdOut,
|
|
|
|
IN SHELL_FILE_HANDLE *OldStdErr,
|
|
|
|
IN SYSTEM_TABLE_INFO *SystemTableInfo
|
2010-09-14 07:18:09 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
SPLIT_LIST *Split;
|
2010-11-16 23:31:47 +01:00
|
|
|
|
2018-06-27 15:13:38 +02:00
|
|
|
if (ShellParameters == NULL
|
2010-11-16 23:31:47 +01:00
|
|
|
||OldStdIn == NULL
|
|
|
|
||OldStdOut == NULL
|
|
|
|
||OldStdErr == NULL
|
|
|
|
||SystemTableInfo == NULL) {
|
|
|
|
return (EFI_INVALID_PARAMETER);
|
|
|
|
}
|
2010-09-14 07:18:09 +02:00
|
|
|
if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) {
|
|
|
|
Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link);
|
|
|
|
} else {
|
|
|
|
Split = NULL;
|
|
|
|
}
|
2010-11-16 23:31:47 +01:00
|
|
|
if (ShellParameters->StdIn != *OldStdIn) {
|
2010-09-14 07:18:09 +02:00
|
|
|
if ((Split != NULL && Split->SplitStdIn != ShellParameters->StdIn) || Split == NULL) {
|
|
|
|
gEfiShellProtocol->CloseFile(ShellParameters->StdIn);
|
|
|
|
}
|
2010-11-16 23:31:47 +01:00
|
|
|
ShellParameters->StdIn = *OldStdIn;
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
2010-11-16 23:31:47 +01:00
|
|
|
if (ShellParameters->StdOut != *OldStdOut) {
|
2010-09-14 07:18:09 +02:00
|
|
|
if ((Split != NULL && Split->SplitStdOut != ShellParameters->StdOut) || Split == NULL) {
|
|
|
|
gEfiShellProtocol->CloseFile(ShellParameters->StdOut);
|
|
|
|
}
|
2010-11-16 23:31:47 +01:00
|
|
|
ShellParameters->StdOut = *OldStdOut;
|
|
|
|
}
|
|
|
|
if (ShellParameters->StdErr != *OldStdErr) {
|
|
|
|
gEfiShellProtocol->CloseFile(ShellParameters->StdErr);
|
|
|
|
ShellParameters->StdErr = *OldStdErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gST->ConIn != SystemTableInfo->ConIn) {
|
|
|
|
CloseSimpleTextInOnFile(gST->ConIn);
|
|
|
|
gST->ConIn = SystemTableInfo->ConIn;
|
|
|
|
gST->ConsoleInHandle = SystemTableInfo->ConInHandle;
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
2010-11-16 23:31:47 +01:00
|
|
|
if (gST->ConOut != SystemTableInfo->ConOut) {
|
|
|
|
CloseSimpleTextOutOnFile(gST->ConOut);
|
|
|
|
gST->ConOut = SystemTableInfo->ConOut;
|
|
|
|
gST->ConsoleOutHandle = SystemTableInfo->ConOutHandle;
|
|
|
|
}
|
2012-08-17 05:58:17 +02:00
|
|
|
if (gST->StdErr != SystemTableInfo->ErrOut) {
|
2010-11-16 23:31:47 +01:00
|
|
|
CloseSimpleTextOutOnFile(gST->StdErr);
|
2012-08-17 05:58:17 +02:00
|
|
|
gST->StdErr = SystemTableInfo->ErrOut;
|
|
|
|
gST->StandardErrorHandle = SystemTableInfo->ErrOutHandle;
|
2010-11-16 23:31:47 +01:00
|
|
|
}
|
|
|
|
|
2011-10-14 01:05:08 +02:00
|
|
|
CalculateEfiHdrCrc(&gST->Hdr);
|
|
|
|
|
2010-09-14 07:18:09 +02:00
|
|
|
return (EFI_SUCCESS);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
Funcion will replace the current Argc and Argv in the ShellParameters protocol
|
|
|
|
structure by parsing NewCommandLine. The current values are returned to the
|
|
|
|
user.
|
|
|
|
|
|
|
|
If OldArgv or OldArgc is NULL then that value is not returned.
|
|
|
|
|
2011-09-02 10:05:34 +02:00
|
|
|
@param[in, out] ShellParameters Pointer to parameter structure to modify.
|
|
|
|
@param[in] NewCommandLine The new command line to parse and use.
|
2015-11-09 03:29:31 +01:00
|
|
|
@param[in] Type The type of operation.
|
2011-09-02 10:05:34 +02:00
|
|
|
@param[out] OldArgv Pointer to old list of parameters.
|
|
|
|
@param[out] OldArgc Pointer to old number of items in Argv list.
|
2010-09-14 07:18:09 +02:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
UpdateArgcArgv(
|
|
|
|
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
|
|
|
|
IN CONST CHAR16 *NewCommandLine,
|
2015-11-09 03:29:31 +01:00
|
|
|
IN SHELL_OPERATION_TYPES Type,
|
2010-09-14 07:18:09 +02:00
|
|
|
OUT CHAR16 ***OldArgv OPTIONAL,
|
|
|
|
OUT UINTN *OldArgc OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
2015-11-09 03:29:31 +01:00
|
|
|
BOOLEAN StripParamQuotation;
|
2018-06-27 15:13:38 +02:00
|
|
|
|
2010-09-14 07:18:09 +02:00
|
|
|
ASSERT(ShellParameters != NULL);
|
2015-11-09 03:29:31 +01:00
|
|
|
StripParamQuotation = TRUE;
|
2010-09-14 07:18:09 +02:00
|
|
|
|
|
|
|
if (OldArgc != NULL) {
|
|
|
|
*OldArgc = ShellParameters->Argc;
|
|
|
|
}
|
|
|
|
if (OldArgc != NULL) {
|
|
|
|
*OldArgv = ShellParameters->Argv;
|
|
|
|
}
|
|
|
|
|
2015-11-09 03:29:31 +01:00
|
|
|
if (Type == Script_File_Name) {
|
|
|
|
StripParamQuotation = FALSE;
|
|
|
|
}
|
2018-06-27 15:13:38 +02:00
|
|
|
|
|
|
|
return ParseCommandLineToArgs( NewCommandLine,
|
|
|
|
StripParamQuotation,
|
|
|
|
&(ShellParameters->Argv),
|
2015-11-09 03:29:31 +01:00
|
|
|
&(ShellParameters->Argc)
|
|
|
|
);
|
2010-09-14 07:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Funcion will replace the current Argc and Argv in the ShellParameters protocol
|
|
|
|
structure with Argv and Argc. The current values are de-allocated and the
|
|
|
|
OldArgv must not be deallocated by the caller.
|
|
|
|
|
2011-09-02 10:05:34 +02:00
|
|
|
@param[in, out] ShellParameters pointer to parameter structure to modify
|
|
|
|
@param[in] OldArgv pointer to old list of parameters
|
|
|
|
@param[in] OldArgc pointer to old number of items in Argv list
|
2010-09-14 07:18:09 +02:00
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
RestoreArgcArgv(
|
|
|
|
IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
|
|
|
|
IN CHAR16 ***OldArgv,
|
|
|
|
IN UINTN *OldArgc
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN LoopCounter;
|
|
|
|
ASSERT(ShellParameters != NULL);
|
|
|
|
ASSERT(OldArgv != NULL);
|
|
|
|
ASSERT(OldArgc != NULL);
|
|
|
|
|
|
|
|
if (ShellParameters->Argv != NULL) {
|
|
|
|
for ( LoopCounter = 0
|
|
|
|
; LoopCounter < ShellParameters->Argc
|
|
|
|
; LoopCounter++
|
|
|
|
){
|
|
|
|
FreePool(ShellParameters->Argv[LoopCounter]);
|
|
|
|
}
|
|
|
|
FreePool(ShellParameters->Argv);
|
|
|
|
}
|
|
|
|
ShellParameters->Argv = *OldArgv;
|
|
|
|
*OldArgv = NULL;
|
|
|
|
ShellParameters->Argc = *OldArgc;
|
|
|
|
*OldArgc = 0;
|
|
|
|
}
|