Revision: 15011
http://sourceforge.net/p/edk2/code/15011
Author: jcarsey
Date: 2013-12-20 01:13:36 +0000 (Fri, 20 Dec 2013)
Log Message:
-----------
ShellPkg: pre-verify split commands
This makes sure that all parts of commands split via pipe operation are valid
before starting.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <[email protected]>
Modified Paths:
--------------
trunk/edk2/ShellPkg/Application/Shell/Shell.c
trunk/edk2/ShellPkg/Application/Shell/Shell.h
Modified: trunk/edk2/ShellPkg/Application/Shell/Shell.c
===================================================================
--- trunk/edk2/ShellPkg/Application/Shell/Shell.c 2013-12-19 22:09:17 UTC
(rev 15010)
+++ trunk/edk2/ShellPkg/Application/Shell/Shell.c 2013-12-20 01:13:36 UTC
(rev 15011)
@@ -1596,7 +1596,97 @@
return (UNKNOWN_INVALID);
}
+EFI_STATUS
+EFIAPI
+IsValidSplit(
+ IN CONST CHAR16 *CmdLine
+ )
+{
+ CHAR16 *Temp;
+ CHAR16 *FirstParameter;
+ CHAR16 *TempWalker;
+ EFI_STATUS Status;
+
+ Temp = NULL;
+
+ Temp = StrnCatGrow(&Temp, NULL, CmdLine, 0);
+ if (Temp == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
+
+ FirstParameter = StrStr(Temp, L"|");
+ if (FirstParameter != NULL) {
+ *FirstParameter = CHAR_NULL;
+ }
+
+ FirstParameter = NULL;
+
+ //
+ // Process the command line
+ //
+ Status = ProcessCommandLineToFinal(&Temp);
+
+ if (!EFI_ERROR(Status)) {
+ FirstParameter = AllocateZeroPool(StrSize(CmdLine));
+ if (FirstParameter == NULL) {
+ SHELL_FREE_NON_NULL(Temp);
+ return (EFI_OUT_OF_RESOURCES);
+ }
+ TempWalker = (CHAR16*)Temp;
+ GetNextParameter(&TempWalker, &FirstParameter);
+
+ if (GetOperationType(FirstParameter) == UNKNOWN_INVALID) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND),
ShellInfoObject.HiiHandle, FirstParameter);
+ SetLastError(SHELL_NOT_FOUND);
+ Status = EFI_NOT_FOUND;
+ }
+ }
+
+ SHELL_FREE_NON_NULL(Temp);
+ SHELL_FREE_NON_NULL(FirstParameter);
+ return Status;
+}
+
/**
+ Determine if a command line contains with a split contains only valid
commands
+
+ @param[in] CmdLine The command line to parse.
+
+ @retval EFI_SUCCESS CmdLine has only valid commands, application, or has
no split.
+ @retval EFI_ABORTED CmdLine has at least one invalid command or
application.
+**/
+EFI_STATUS
+EFIAPI
+VerifySplit(
+ IN CONST CHAR16 *CmdLine
+ )
+{
+ CONST CHAR16 *TempSpot;
+ EFI_STATUS Status;
+
+ //
+ // Verify up to the pipe or end character
+ //
+ Status = IsValidSplit(CmdLine);
+ if (EFI_ERROR(Status)) {
+ return (Status);
+ }
+
+ //
+ // If this was the only item, then get out
+ //
+ if (!ContainsSplit(CmdLine)) {
+ return (EFI_SUCCESS);
+ }
+
+ //
+ // recurse to verify the next item
+ //
+ TempSpot = FindSplit(CmdLine)+1;
+ return (VerifySplit(TempSpot));
+}
+
+/**
Process a split based operation.
@param[in] CmdLine pointer to the command line to process
@@ -1613,6 +1703,11 @@
SPLIT_LIST *Split;
EFI_STATUS Status;
+ Status = VerifySplit(CmdLine);
+ if (EFI_ERROR(Status)) {
+ return (Status);
+ }
+
Split = NULL;
//
@@ -1728,7 +1823,7 @@
EFI_STATUS
EFIAPI
SetLastError(
- IN CONST UINT64 ErrorCode
+ IN CONST SHELL_STATUS ErrorCode
)
{
CHAR16 LeString[19];
@@ -1943,7 +2038,7 @@
//
if (!EFI_ERROR(ShellIsDirectory(CommandWithPath))) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND),
ShellInfoObject.HiiHandle, FirstParameter);
- SetLastError(EFI_NOT_FOUND);
+ SetLastError(SHELL_NOT_FOUND);
}
switch (Type) {
case SCRIPT_FILE_NAME:
@@ -2129,7 +2224,7 @@
// Whatever was typed, it was invalid.
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND),
ShellInfoObject.HiiHandle, FirstParameter);
- SetLastError(EFI_NOT_FOUND);
+ SetLastError(SHELL_NOT_FOUND);
break;
}
Modified: trunk/edk2/ShellPkg/Application/Shell/Shell.h
===================================================================
--- trunk/edk2/ShellPkg/Application/Shell/Shell.h 2013-12-19 22:09:17 UTC
(rev 15010)
+++ trunk/edk2/ShellPkg/Application/Shell/Shell.h 2013-12-20 01:13:36 UTC
(rev 15011)
@@ -133,6 +133,32 @@
} SHELL_OPERATION_TYPES;
/**
+ Converts the command line to it's post-processed form. this replaces
variables and alias' per UEFI Shell spec.
+
+ @param[in,out] CmdLine pointer to the command line to update
+
+ @retval EFI_SUCCESS The operation was successful
+ @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
+ @return some other error occured
+**/
+EFI_STATUS
+EFIAPI
+ProcessCommandLineToFinal(
+ IN OUT CHAR16 **CmdLine
+ );
+
+/**
+ Function to update the shell variable "lasterror"
+
+ @param[in] ErrorCode the error code to put into lasterror
+**/
+EFI_STATUS
+EFIAPI
+SetLastError(
+ IN CONST SHELL_STATUS ErrorCode
+ );
+
+/**
Sets all the alias' that were registered with the ShellCommandLib library.
@retval EFI_SUCCESS all init commands were run sucessfully.
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits