]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellLevel1CommandsLib/Goto.c
pointer verification (not NULL) and buffer overrun fixes.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel1CommandsLib / Goto.c
CommitLineData
a405b86d 1/** @file\r
2 Main file for goto shell level 1 function.\r
3\r
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "UefiShellLevel1CommandsLib.h"\r
16\r
17/**\r
18 Function for 'goto' command.\r
19\r
20 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
21 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
22**/\r
23SHELL_STATUS\r
24EFIAPI\r
25ShellCommandRunGoto (\r
26 IN EFI_HANDLE ImageHandle,\r
27 IN EFI_SYSTEM_TABLE *SystemTable\r
28 )\r
29{\r
30 EFI_STATUS Status;\r
31 LIST_ENTRY *Package;\r
32 CHAR16 *ProblemParam;\r
33 SHELL_STATUS ShellStatus;\r
34 CHAR16 *CompareString;\r
35 UINTN Size;\r
36\r
37 ShellStatus = SHELL_SUCCESS;\r
38 CompareString = NULL;\r
39\r
40 //\r
41 // initialize the shell lib (we must be in non-auto-init...)\r
42 //\r
43 Status = ShellInitialize();\r
44 ASSERT_EFI_ERROR(Status);\r
45\r
46 Status = CommandInit();\r
47 ASSERT_EFI_ERROR(Status);\r
48\r
49 if (!gEfiShellProtocol->BatchIsActive()) {\r
50 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Goto");\r
51 return (SHELL_UNSUPPORTED);\r
52 }\r
53\r
54 //\r
55 // parse the command line\r
56 //\r
57 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);\r
58 if (EFI_ERROR(Status)) {\r
59 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
60 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, ProblemParam);\r
61 FreePool(ProblemParam);\r
62 ShellStatus = SHELL_INVALID_PARAMETER;\r
63 } else {\r
64 ASSERT(FALSE);\r
65 }\r
66 } else {\r
67 if (ShellCommandLineGetRawValue(Package, 2) != NULL) {\r
68 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle);\r
69 ShellStatus = SHELL_INVALID_PARAMETER;\r
70 } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {\r
71 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle);\r
72 ShellStatus = SHELL_INVALID_PARAMETER;\r
73 } else {\r
74 Size = 0;\r
75 ASSERT((CompareString == NULL && Size == 0) || (CompareString != NULL));\r
76 CompareString = StrnCatGrow(&CompareString, &Size, L":", 0);\r
77 CompareString = StrnCatGrow(&CompareString, &Size, ShellCommandLineGetRawValue(Package, 1), 0);\r
78 //\r
79 // Check forwards and then backwards for a label...\r
80 //\r
81 if (!MoveToTag(GetNextNode, L"endfor", L"for", CompareString, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, TRUE)) {\r
33c031ee 82 ShellPrintHiiEx(\r
83 -1, \r
84 -1, \r
85 NULL, \r
86 STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r
87 gShellLevel1HiiHandle, \r
88 CompareString, \r
89 L"Goto", \r
90 ShellCommandGetCurrentScriptFile()!=NULL\r
91 &&ShellCommandGetCurrentScriptFile()->CurrentCommand!=NULL\r
92 ?ShellCommandGetCurrentScriptFile()->CurrentCommand->Line:0);\r
a405b86d 93 ShellStatus = SHELL_NOT_FOUND;\r
94 }\r
95 FreePool(CompareString);\r
96 }\r
97 ShellCommandLineFreeVarList (Package);\r
98 }\r
99\r
100 return (ShellStatus);\r
101}\r
102\r