]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Refine code to make it more safely.
authorEric Dong <eric.dong@intel.com>
Thu, 26 Jun 2014 01:38:46 +0000 (01:38 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 26 Jun 2014 01:38:46 +0000 (01:38 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15593 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Application/Shell/Shell.c
ShellPkg/Application/Shell/ShellProtocol.c
ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c
ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c
ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c
ShellPkg/Library/UefiShellLevel1CommandsLib/For.c

index 4abeafcd44474f08a9c45e05ff263bf4ada4d3f0..2f1e3eb65c89ecdce0a16f4cddd9f17109f8ea78 100644 (file)
@@ -509,6 +509,7 @@ UefiMain (
           // Reset page break back to default.\r
           //\r
           ShellInfoObject.PageBreakEnabled        = PcdGetBool(PcdShellPageBreakDefault);\r
+          ASSERT (ShellInfoObject.ConsoleInfo != NULL);\r
           ShellInfoObject.ConsoleInfo->Enabled    = TRUE;\r
           ShellInfoObject.ConsoleInfo->RowCounter = 0;\r
 \r
@@ -2091,6 +2092,7 @@ ProcessCommandLineToFinal(
   if (EFI_ERROR(Status)) {\r
     return (Status);\r
   }\r
+  ASSERT (*CmdLine != NULL);\r
 \r
   TrimSpaces(CmdLine);\r
 \r
index e4680139d0b1ad30a7b305debd8e1d4c001f3fce..3d01283b60a1326495b47a0021dda177e8efe9df 100644 (file)
@@ -460,6 +460,7 @@ EfiShellGetFilePathFromDevicePath(
           ASSERT((PathForReturn == NULL && PathSize == 0) || (PathForReturn != NULL));\r
 \r
           AlignedNode = AllocateCopyPool (DevicePathNodeLength(FilePath), FilePath);\r
+          ASSERT (AlignedNode != NULL);\r
 \r
           // File Path Device Path Nodes 'can optionally add a "\" separator to\r
           //  the beginning and/or the end of the Path Name string.'\r
index b19d8d9fb8490d6c47277e864a4bdea5bba16de2..483aa5855e673083a6e4bf562c9ad91483cae5c8 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for bcfg shell Debug1 function.\r
 \r
-  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -1027,12 +1027,14 @@ BcfgDisplayDumpDebug1(
         Buffer);\r
     if (Status == EFI_BUFFER_TOO_SMALL) {\r
       Buffer = AllocateZeroPool(BufferSize);\r
-      Status = gRT->GetVariable(\r
-          VariableName,\r
-          (EFI_GUID*)&gEfiGlobalVariableGuid,\r
-          NULL,\r
-          &BufferSize,\r
-          Buffer);\r
+      if (Buffer != NULL) {\r
+        Status = gRT->GetVariable(\r
+            VariableName,\r
+            (EFI_GUID*)&gEfiGlobalVariableGuid,\r
+            NULL,\r
+            &BufferSize,\r
+            Buffer);\r
+      }\r
     }\r
 \r
     if (EFI_ERROR(Status) || Buffer == NULL) {\r
@@ -1042,8 +1044,12 @@ BcfgDisplayDumpDebug1(
 \r
     if ((*(UINT16*)(Buffer+4)) != 0) {\r
       DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4));\r
-      CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));\r
-      DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);\r
+      if (DevPath != NULL) {\r
+        CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));\r
+        DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);\r
+      } else {\r
+        DevPathString = NULL;\r
+      }\r
     } else {\r
       DevPath       = NULL;\r
       DevPathString = NULL;\r
@@ -1213,12 +1219,16 @@ ShellCommandRunBcfg (
         CurrentOperation.Order);\r
       if (Status == EFI_BUFFER_TOO_SMALL) {\r
         CurrentOperation.Order = AllocateZeroPool(Length+(4*sizeof(CurrentOperation.Order[0])));\r
-        Status = gRT->GetVariable(\r
-          CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",\r
-          (EFI_GUID*)&gEfiGlobalVariableGuid,\r
-          NULL,\r
-          &Length,\r
-          CurrentOperation.Order);\r
+        if (CurrentOperation.Order != NULL) {\r
+          Status = gRT->GetVariable(\r
+            CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",\r
+            (EFI_GUID*)&gEfiGlobalVariableGuid,\r
+            NULL,\r
+            &Length,\r
+            CurrentOperation.Order);\r
+        } else {\r
+          ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+        }\r
       }\r
     }\r
 \r
index 179559833eec5d17bc52ee0926f3409cc7e51854..897700bd341bd7a0b5e085fc8f2ac26314fe3cac 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implements filebuffer interface functions.\r
 \r
-  Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -489,8 +489,9 @@ FileBufferPrintLine (
 \r
   CHAR16  *Buffer;\r
   UINTN   Limit;\r
-  CHAR16  PrintLine[200];\r
-  CHAR16  PrintLine2[250];\r
+  CHAR16  *PrintLine;\r
+  CHAR16  *PrintLine2;\r
+  UINTN   BufLen; \r
 \r
   //\r
   // print start from correct character\r
@@ -502,13 +503,21 @@ FileBufferPrintLine (
     Limit = 0;\r
   }\r
 \r
-  StrnCpy (PrintLine, Buffer, MIN(MIN(Limit,MainEditor.ScreenSize.Column), 200));\r
+  BufLen = (MainEditor.ScreenSize.Column + 1) * sizeof (CHAR16);\r
+  PrintLine = AllocatePool (BufLen);\r
+  ASSERT (PrintLine != NULL);\r
+\r
+  StrnCpy (PrintLine, Buffer, MIN(Limit, MainEditor.ScreenSize.Column));\r
   for (; Limit < MainEditor.ScreenSize.Column; Limit++) {\r
     PrintLine[Limit] = L' ';\r
   }\r
 \r
   PrintLine[MainEditor.ScreenSize.Column] = CHAR_NULL;\r
-  ShellCopySearchAndReplace(PrintLine, PrintLine2,  250, L"%", L"^%", FALSE, FALSE);\r
+\r
+  PrintLine2 = AllocatePool (BufLen * 2);\r
+  ASSERT (PrintLine2 != NULL);\r
+\r
+  ShellCopySearchAndReplace(PrintLine, PrintLine2, BufLen * 2, L"%", L"^%", FALSE, FALSE);\r
 \r
   ShellPrintEx (\r
     0,\r
@@ -517,6 +526,9 @@ FileBufferPrintLine (
     PrintLine2\r
     );\r
 \r
+  FreePool (PrintLine);\r
+  FreePool (PrintLine2);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
index 636acb21dbaccf48fcf0d0bc31f3b5f4738157fe..29411df11e87714ff1cc2b66485a37ca54b3c454 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for Mm shell Debug1 function.\r
 \r
-  Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -229,6 +229,7 @@ ShellCommandRunMm (
   SHELL_STATUS                    ShellStatus;\r
   CONST CHAR16                    *Temp;\r
 \r
+  Value         = 0;\r
   Address       = 0;\r
   PciEAddress   = 0;\r
   IoDev         = NULL;\r
index b91b34ffaeb1cc544509044629fdb8f3b1ebd270..a7893f5eeede79f85e938ca467b8611e49eaa816 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for bcfg shell Install1 function.\r
 \r
-  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -1040,8 +1040,12 @@ BcfgDisplayDumpInstall1(
 \r
     if ((*(UINT16*)(Buffer+4)) != 0) {\r
       DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4));\r
-      CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));\r
-      DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);\r
+      if (DevPath == NULL) {\r
+        DevPathString = NULL;\r
+      } else {\r
+        CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));\r
+        DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);\r
+      }\r
     } else {\r
       DevPath       = NULL;\r
       DevPathString = NULL;\r
@@ -1211,12 +1215,16 @@ ShellCommandRunBcfgInstall (
         CurrentOperation.Order);\r
       if (Status == EFI_BUFFER_TOO_SMALL) {\r
         CurrentOperation.Order = AllocateZeroPool(Length+(4*sizeof(CurrentOperation.Order[0])));\r
-        Status = gRT->GetVariable(\r
-          CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",\r
-          (EFI_GUID*)&gEfiGlobalVariableGuid,\r
-          NULL,\r
-          &Length,\r
-          CurrentOperation.Order);\r
+        if (CurrentOperation.Order == NULL) {\r
+          ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+        } else {\r
+          Status = gRT->GetVariable(\r
+            CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",\r
+            (EFI_GUID*)&gEfiGlobalVariableGuid,\r
+            NULL,\r
+            &Length,\r
+            CurrentOperation.Order);\r
+        }\r
       }\r
     }\r
 \r
index 85b85d8dcfa7bcb48a49969296c2c867d6acf86e..4fdbdd051d4c48b439b1b74c4c8b8fe37c79d1cb 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for endfor and for shell level 1 functions.\r
 \r
-  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -333,7 +333,7 @@ ShellCommandRunFor (
   CurrentScriptFile = ShellCommandGetCurrentScriptFile();\r
   ASSERT(CurrentScriptFile != NULL);\r
 \r
-  if (CurrentScriptFile->CurrentCommand->Data == NULL) {\r
+  if ((CurrentScriptFile->CurrentCommand != NULL) && (CurrentScriptFile->CurrentCommand->Data == NULL)) {\r
     FirstPass = TRUE;\r
 \r
     //\r
@@ -348,8 +348,7 @@ ShellCommandRunFor (
         gShellLevel1HiiHandle, \r
         L"EndFor", \r
         L"For", \r
-        CurrentScriptFile->CurrentCommand!=NULL\r
-          ?CurrentScriptFile->CurrentCommand->Line:0);\r
+        CurrentScriptFile->CurrentCommand->Line);\r
       return (SHELL_DEVICE_ERROR);\r
     }\r
 \r
@@ -459,9 +458,7 @@ ShellCommandRunFor (
             STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r
             gShellLevel1HiiHandle, \r
             ArgSet, \r
-            CurrentScriptFile!=NULL \r
-              && CurrentScriptFile->CurrentCommand!=NULL\r
-              ? CurrentScriptFile->CurrentCommand->Line:0);\r
+            CurrentScriptFile->CurrentCommand->Line);\r
           ShellStatus = SHELL_INVALID_PARAMETER;\r
         } else {\r
           TempSpot = StrStr(ArgSetWalker, L")");\r
@@ -483,9 +480,7 @@ ShellCommandRunFor (
               NULL, \r
               STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r
               gShellLevel1HiiHandle, \r
-              CurrentScriptFile!=NULL \r
-                && CurrentScriptFile->CurrentCommand!=NULL\r
-                ? CurrentScriptFile->CurrentCommand->Line:0);\r
+              CurrentScriptFile->CurrentCommand->Line);\r
             ShellStatus = SHELL_INVALID_PARAMETER;\r
           } else {\r
             *TempSpot = CHAR_NULL;\r
@@ -501,9 +496,7 @@ ShellCommandRunFor (
                 STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r
                 gShellLevel1HiiHandle, \r
                 ArgSet, \r
-                CurrentScriptFile!=NULL \r
-                  && CurrentScriptFile->CurrentCommand!=NULL\r
-                  ? CurrentScriptFile->CurrentCommand->Line:0);\r
+                CurrentScriptFile->CurrentCommand->Line);\r
               ShellStatus = SHELL_INVALID_PARAMETER;\r
             } else {\r
               if (ArgSetWalker[0] == L'-') {\r
@@ -523,9 +516,7 @@ ShellCommandRunFor (
                   STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r
                   gShellLevel1HiiHandle, \r
                   ArgSet, \r
-                  CurrentScriptFile!=NULL \r
-                    && CurrentScriptFile->CurrentCommand!=NULL\r
-                    ? CurrentScriptFile->CurrentCommand->Line:0);\r
+                  CurrentScriptFile->CurrentCommand->Line);\r
                 ShellStatus = SHELL_INVALID_PARAMETER;\r
               } else {\r
                 if (ArgSetWalker[0] == L'-') {\r
@@ -552,9 +543,7 @@ ShellCommandRunFor (
                       STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r
                       gShellLevel1HiiHandle, \r
                       ArgSet, \r
-                      CurrentScriptFile!=NULL \r
-                        && CurrentScriptFile->CurrentCommand!=NULL\r
-                        ? CurrentScriptFile->CurrentCommand->Line:0);\r
+                      CurrentScriptFile->CurrentCommand->Line);\r
                     ShellStatus = SHELL_INVALID_PARAMETER;\r
                   } else {\r
                     if (*ArgSetWalker == L')') {\r
@@ -574,9 +563,7 @@ ShellCommandRunFor (
                           STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r
                           gShellLevel1HiiHandle, \r
                           ArgSet, \r
-                          CurrentScriptFile!=NULL \r
-                            && CurrentScriptFile->CurrentCommand!=NULL\r
-                            ? CurrentScriptFile->CurrentCommand->Line:0);\r
+                          CurrentScriptFile->CurrentCommand->Line);\r
                         ShellStatus = SHELL_INVALID_PARAMETER;\r
                       }\r
                     }\r