]> git.proxmox.com Git - mirror_edk2.git/commitdiff
pointer verification (not NULL) and buffer overrun fixes.
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 30 Mar 2011 19:33:03 +0000 (19:33 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 30 Mar 2011 19:33:03 +0000 (19:33 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11459 6f19259b-4bc3-4df7-8a09-765794883524

21 files changed:
ShellPkg/Application/Shell/Shell.c
ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c
ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c
ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c
ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEdit.c
ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/Misc.c
ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c
ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/EventLogInfo.c
ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c
ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.h
ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c
ShellPkg/Library/UefiShellLevel1CommandsLib/For.c
ShellPkg/Library/UefiShellLevel1CommandsLib/Goto.c
ShellPkg/Library/UefiShellLevel1CommandsLib/If.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c
ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c
ShellPkg/Library/UefiShellLevel2CommandsLib/Vol.c
ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c
ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c

index 17943531dbb08b13aa00d5a2e13a85c8d0a04776..ecd48cdd78719149670ff1f464e955e9d1963b52 100644 (file)
@@ -731,7 +731,7 @@ ProcessCommandLine(
     ShellInfoObject.ShellInitSettings.Delay = 0;\r
   } else if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay) {\r
     TempConst = ShellCommandLineGetValue(Package, L"-delay");\r
     ShellInfoObject.ShellInitSettings.Delay = 0;\r
   } else if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay) {\r
     TempConst = ShellCommandLineGetValue(Package, L"-delay");\r
-    if (*TempConst == L':') {\r
+    if (TempConst != NULL && *TempConst == L':') {\r
       TempConst++;\r
     }\r
     if (TempConst != NULL && !EFI_ERROR(ShellConvertStringToUint64(TempConst, &Intermediate, FALSE, FALSE))) {\r
       TempConst++;\r
     }\r
     if (TempConst != NULL && !EFI_ERROR(ShellConvertStringToUint64(TempConst, &Intermediate, FALSE, FALSE))) {\r
index 73e8c576372af350d0e60b438c076724cd896ee5..d278ee60e6696d7d717670a1fb99cb53a089821f 100644 (file)
@@ -265,27 +265,31 @@ BcfgAddDebug1(
     FilePathSize = GetDevicePathSize (FilePath);\r
 \r
     TempByteBuffer = AllocateZeroPool(sizeof(UINT32) + sizeof(UINT16) + DescSize + FilePathSize);\r
     FilePathSize = GetDevicePathSize (FilePath);\r
 \r
     TempByteBuffer = AllocateZeroPool(sizeof(UINT32) + sizeof(UINT16) + DescSize + FilePathSize);\r
-    TempByteStart  = TempByteBuffer;\r
-    *((UINT32 *) TempByteBuffer) = LOAD_OPTION_ACTIVE;      // Attributes\r
-    TempByteBuffer += sizeof (UINT32);\r
+    if (TempByteBuffer != NULL) {\r
+      TempByteStart  = TempByteBuffer;\r
+      *((UINT32 *) TempByteBuffer) = LOAD_OPTION_ACTIVE;      // Attributes\r
+      TempByteBuffer += sizeof (UINT32);\r
 \r
 \r
-    *((UINT16 *) TempByteBuffer) = (UINT16)FilePathSize;    // FilePathListLength\r
-    TempByteBuffer += sizeof (UINT16);\r
+      *((UINT16 *) TempByteBuffer) = (UINT16)FilePathSize;    // FilePathListLength\r
+      TempByteBuffer += sizeof (UINT16);\r
 \r
 \r
-    CopyMem (TempByteBuffer, Desc, DescSize);\r
-    TempByteBuffer += DescSize;\r
-    CopyMem (TempByteBuffer, FilePath, FilePathSize);\r
+      CopyMem (TempByteBuffer, Desc, DescSize);\r
+      TempByteBuffer += DescSize;\r
+      CopyMem (TempByteBuffer, FilePath, FilePathSize);\r
 \r
 \r
-    UnicodeSPrint (OptionStr, sizeof(OptionStr), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", TargetLocation);\r
-    Status = gRT->SetVariable (\r
-          OptionStr,\r
-          &gEfiGlobalVariableGuid,\r
-          EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,\r
-          sizeof(UINT32) + sizeof(UINT16) + DescSize + FilePathSize,\r
-          TempByteStart\r
-         );\r
-\r
-    FreePool(TempByteStart);\r
+      UnicodeSPrint (OptionStr, sizeof(OptionStr), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", TargetLocation);\r
+      Status = gRT->SetVariable (\r
+            OptionStr,\r
+            &gEfiGlobalVariableGuid,\r
+            EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,\r
+            sizeof(UINT32) + sizeof(UINT16) + DescSize + FilePathSize,\r
+            TempByteStart\r
+           );\r
+\r
+      FreePool(TempByteStart);\r
+    } else {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+    }\r
 \r
     if (EFI_ERROR(Status)) {\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellDebug1HiiHandle, OptionStr, Status);\r
 \r
     if (EFI_ERROR(Status)) {\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellDebug1HiiHandle, OptionStr, Status);\r
@@ -385,22 +389,25 @@ BcfgRemoveDebug1(
     return (SHELL_INVALID_PARAMETER);\r
   }\r
   NewOrder = AllocateZeroPool(OrderCount*sizeof(CurrentOrder[0]));\r
     return (SHELL_INVALID_PARAMETER);\r
   }\r
   NewOrder = AllocateZeroPool(OrderCount*sizeof(CurrentOrder[0]));\r
-  NewCount = OrderCount;\r
-  CopyMem(NewOrder, CurrentOrder, OrderCount*sizeof(CurrentOrder[0]));\r
-  for (LoopVar = 0 ; LoopVar < OrderCount ; LoopVar++){\r
-    if (NewOrder[LoopVar] == Location) {\r
-      CopyMem(NewOrder+LoopVar, NewOrder+LoopVar+1, (OrderCount - LoopVar - 1)*sizeof(CurrentOrder[0]));\r
-      NewCount--;\r
+  if (NewOrder != NULL) {\r
+    NewCount = OrderCount;\r
+    CopyMem(NewOrder, CurrentOrder, OrderCount*sizeof(CurrentOrder[0]));\r
+    for (LoopVar = 0 ; LoopVar < OrderCount ; LoopVar++){\r
+      if (NewOrder[LoopVar] == Location) {\r
+        CopyMem(NewOrder+LoopVar, NewOrder+LoopVar+1, (OrderCount - LoopVar - 1)*sizeof(CurrentOrder[0]));\r
+        NewCount--;\r
+      }\r
     }\r
     }\r
+    Status = gRT->SetVariable(\r
+      Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",\r
+      (EFI_GUID*)&gEfiGlobalVariableGuid,\r
+      EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,\r
+      NewCount*sizeof(NewOrder[0]),\r
+      NewOrder);\r
+    FreePool(NewOrder);\r
+  } else {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
   }\r
   }\r
-  Status = gRT->SetVariable(\r
-    Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",\r
-    (EFI_GUID*)&gEfiGlobalVariableGuid,\r
-    EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,\r
-    NewCount*sizeof(NewOrder[0]),\r
-    NewOrder);\r
-  FreePool(NewOrder);\r
-\r
   if (EFI_ERROR(Status)) {\r
     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellDebug1HiiHandle, Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder", Status);\r
     return (SHELL_INVALID_PARAMETER);\r
   if (EFI_ERROR(Status)) {\r
     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellDebug1HiiHandle, Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder", Status);\r
     return (SHELL_INVALID_PARAMETER);\r
index 5b48481913501799bfc0aae15db3dd65c38764b4..fcd0de5cb5f67b14ca99a9dcf713d1d480d58059 100644 (file)
@@ -247,10 +247,10 @@ MoveLine (
   // if > 0, the advance\r
   //\r
   if (Count <= 0) {\r
   // if > 0, the advance\r
   //\r
   if (Count <= 0) {\r
-    AbsCount  = -Count;\r
+    AbsCount  = (UINTN)ABS(Count);\r
     Line      = InternalEditorMiscLineRetreat (AbsCount,MainEditor.FileBuffer->CurrentLine,MainEditor.FileBuffer->ListHead);\r
   } else {\r
     Line      = InternalEditorMiscLineRetreat (AbsCount,MainEditor.FileBuffer->CurrentLine,MainEditor.FileBuffer->ListHead);\r
   } else {\r
-    Line = InternalEditorMiscLineAdvance (Count,MainEditor.FileBuffer->CurrentLine,MainEditor.FileBuffer->ListHead);\r
+    Line = InternalEditorMiscLineAdvance ((UINTN)Count,MainEditor.FileBuffer->CurrentLine,MainEditor.FileBuffer->ListHead);\r
   }\r
 \r
   return Line;\r
   }\r
 \r
   return Line;\r
@@ -317,7 +317,7 @@ FileBufferRestoreMousePosition (
         CurrentLine = FileBuffer.CurrentLine;\r
         Line        = MoveLine (FRow - FileBuffer.FilePosition.Row);\r
 \r
         CurrentLine = FileBuffer.CurrentLine;\r
         Line        = MoveLine (FRow - FileBuffer.FilePosition.Row);\r
 \r
-        if (FColumn > Line->Size) {\r
+        if (Line == NULL || FColumn > Line->Size) {\r
           HasCharacter = FALSE;\r
         }\r
 \r
           HasCharacter = FALSE;\r
         }\r
 \r
@@ -500,7 +500,7 @@ FileBufferPrintLine (
     Limit = 0;\r
   }\r
 \r
     Limit = 0;\r
   }\r
 \r
-  StrnCpy (PrintLine, Buffer, Limit > MainEditor.ScreenSize.Column ? MainEditor.ScreenSize.Column : Limit);\r
+  StrnCpy (PrintLine, Buffer, MIN(MIN(Limit,MainEditor.ScreenSize.Column), 200));\r
   for (; Limit < MainEditor.ScreenSize.Column; Limit++) {\r
     PrintLine[Limit] = L' ';\r
   }\r
   for (; Limit < MainEditor.ScreenSize.Column; Limit++) {\r
     PrintLine[Limit] = L' ';\r
   }\r
@@ -1446,7 +1446,7 @@ FileBufferSave (
   //\r
   // if is the old file\r
   //\r
   //\r
   // if is the old file\r
   //\r
-  if (StrCmp (FileName, FileBuffer.FileName) == 0) {\r
+  if (FileBuffer.FileName != NULL && StrCmp (FileName, FileBuffer.FileName) == 0) {\r
     //\r
     // file has not been modified\r
     //\r
     //\r
     // file has not been modified\r
     //\r
@@ -2316,7 +2316,7 @@ FileBufferPageDown (
   //\r
   // if that line, is not that long, so move to the end of that line\r
   //\r
   //\r
   // if that line, is not that long, so move to the end of that line\r
   //\r
-  if (FCol > Line->Size) {\r
+  if (Line != NULL && FCol > Line->Size) {\r
     FCol = Line->Size + 1;\r
   }\r
 \r
     FCol = Line->Size + 1;\r
   }\r
 \r
@@ -2372,7 +2372,7 @@ FileBufferPageUp (
   //\r
   // if that line is not that long, so move to the end of that line\r
   //\r
   //\r
   // if that line is not that long, so move to the end of that line\r
   //\r
-  if (FCol > Line->Size) {\r
+  if (Line != NULL && FCol > Line->Size) {\r
     FCol = Line->Size + 1;\r
   }\r
 \r
     FCol = Line->Size + 1;\r
   }\r
 \r
@@ -2650,10 +2650,10 @@ MoveCurrentLine (
   UINTN           AbsCount;\r
 \r
   if (Count <= 0) {\r
   UINTN           AbsCount;\r
 \r
   if (Count <= 0) {\r
-    AbsCount  = -Count;\r
+    AbsCount  = (UINTN)ABS(Count);\r
     Line      = InternalEditorMiscLineRetreat (AbsCount,MainEditor.FileBuffer->CurrentLine,MainEditor.FileBuffer->ListHead);\r
   } else {\r
     Line      = InternalEditorMiscLineRetreat (AbsCount,MainEditor.FileBuffer->CurrentLine,MainEditor.FileBuffer->ListHead);\r
   } else {\r
-    Line = InternalEditorMiscLineAdvance (Count,MainEditor.FileBuffer->CurrentLine,MainEditor.FileBuffer->ListHead);\r
+    Line = InternalEditorMiscLineAdvance ((UINTN)Count,MainEditor.FileBuffer->CurrentLine,MainEditor.FileBuffer->ListHead);\r
   }\r
 \r
   if (Line == NULL) {\r
   }\r
 \r
   if (Line == NULL) {\r
@@ -2720,7 +2720,7 @@ FileBufferMovePosition (
       //\r
       FileBuffer.FilePosition.Row = NewFilePosRow;\r
       if (RowGap < 0) {\r
       //\r
       FileBuffer.FilePosition.Row = NewFilePosRow;\r
       if (RowGap < 0) {\r
-        Abs = -RowGap;\r
+        Abs = (UINTN)ABS(RowGap);\r
         FileBuffer.DisplayPosition.Row -= Abs;\r
       } else {\r
         FileBuffer.DisplayPosition.Row += RowGap;\r
         FileBuffer.DisplayPosition.Row -= Abs;\r
       } else {\r
         FileBuffer.DisplayPosition.Row += RowGap;\r
index 60e0b75435adad5fa3125074fc9fd64458af5b37..675850cff4661c60f39326993650207e3c6a42aa 100644 (file)
@@ -637,7 +637,7 @@ HBufferImageRestoreMousePosition (
         CurrentLine = HBufferImage.CurrentLine;\r
         Line        = HMoveLine (FRow - HBufferImage.BufferPosition.Row);\r
 \r
         CurrentLine = HBufferImage.CurrentLine;\r
         Line        = HMoveLine (FRow - HBufferImage.BufferPosition.Row);\r
 \r
-        if (FColumn > Line->Size) {\r
+        if (Line == NULL || FColumn > Line->Size) {\r
           HasCharacter = FALSE;\r
         }\r
 \r
           HasCharacter = FALSE;\r
         }\r
 \r
@@ -1620,7 +1620,7 @@ Returns:
       //\r
       HBufferImage.BufferPosition.Row = NewFilePosRow;\r
       if (RowGap <= 0) {\r
       //\r
       HBufferImage.BufferPosition.Row = NewFilePosRow;\r
       if (RowGap <= 0) {\r
-        Abs = -RowGap;\r
+        Abs = (UINTN)ABS(RowGap);\r
         HBufferImage.DisplayPosition.Row -= Abs;\r
       } else {\r
         HBufferImage.DisplayPosition.Row += RowGap;\r
         HBufferImage.DisplayPosition.Row -= Abs;\r
       } else {\r
         HBufferImage.DisplayPosition.Row += RowGap;\r
@@ -1931,7 +1931,7 @@ Returns:
   //\r
   // if that line, is not that long, so move to the end of that line\r
   //\r
   //\r
   // if that line, is not that long, so move to the end of that line\r
   //\r
-  if (FCol > Line->Size) {\r
+  if (Line != NULL && FCol > Line->Size) {\r
     FCol      = Line->Size + 1;\r
     HighBits  = TRUE;\r
   }\r
     FCol      = Line->Size + 1;\r
     HighBits  = TRUE;\r
   }\r
index 57cefb882c02faa5b526490ee600757beafe97fd..fd6387a20a9a78e98e8817dc696259c859a6d245 100644 (file)
@@ -383,7 +383,7 @@ Returns:
   //\r
   // if is the old file\r
   //\r
   //\r
   // if is the old file\r
   //\r
-  if (StrCmp (FileName, HFileImage.FileName) == 0) {\r
+  if (HFileImage.FileName != NULL && FileName != NULL && StrCmp (FileName, HFileImage.FileName) == 0) {\r
     //\r
     // check whether file exists on disk\r
     //\r
     //\r
     // check whether file exists on disk\r
     //\r
index 0a97a6ca29c226dd9f241df3b6fc4542f12553f1..53718c775138928d87c04622a553b2bc79c7d0a9 100644 (file)
@@ -110,7 +110,7 @@ ShellCommandRunHexEdit (
         ShellStatus = SHELL_INVALID_PARAMETER;\r
       } else {\r
         Name      = ShellCommandLineGetRawValue(Package, 1);\r
         ShellStatus = SHELL_INVALID_PARAMETER;\r
       } else {\r
         Name      = ShellCommandLineGetRawValue(Package, 1);\r
-        if (!IsValidFileName(Name)) {\r
+        if (Name == NULL || !IsValidFileName(Name)) {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Name);\r
           ShellStatus = SHELL_INVALID_PARAMETER;\r
         } else {\r
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Name);\r
           ShellStatus = SHELL_INVALID_PARAMETER;\r
         } else {\r
index 8ae21450c4978247828a3e46b5957dca5b477b9c..da11789625635ff730d806e0eb17d25480dd7564 100644 (file)
@@ -256,10 +256,10 @@ Returns:
   //     do not set currentline to Line\r
   //\r
   if (Count <= 0) {\r
   //     do not set currentline to Line\r
   //\r
   if (Count <= 0) {\r
-    AbsCount  = -Count;\r
+    AbsCount  = (UINTN)ABS(Count);\r
     Line      = _HLineRetreat (AbsCount);\r
   } else {\r
     Line      = _HLineRetreat (AbsCount);\r
   } else {\r
-    Line = _HLineAdvance (Count);\r
+    Line = _HLineAdvance ((UINTN)Count);\r
   }\r
 \r
   return Line;\r
   }\r
 \r
   return Line;\r
@@ -297,10 +297,10 @@ Returns:
   // >0: advance\r
   //\r
   if (Count <= 0) {\r
   // >0: advance\r
   //\r
   if (Count <= 0) {\r
-    AbsCount  = -Count;\r
+    AbsCount  = (UINTN)ABS(Count);\r
     Line      = _HLineRetreat (AbsCount);\r
   } else {\r
     Line      = _HLineRetreat (AbsCount);\r
   } else {\r
-    Line = _HLineAdvance (Count);\r
+    Line = _HLineAdvance ((UINTN)Count);\r
   }\r
 \r
   if (Line == NULL) {\r
   }\r
 \r
   if (Line == NULL) {\r
@@ -399,7 +399,10 @@ Returns:
   Lenp        = StrLen (Pat);\r
   Lens        = StrLen (Str);\r
 \r
   Lenp        = StrLen (Pat);\r
   Lens        = StrLen (Str);\r
 \r
-  Failure     = AllocateZeroPool (Lenp * sizeof (INTN));\r
+  Failure     = AllocateZeroPool ((UINTN)(Lenp * sizeof (INTN)));\r
+  if (Failure == NULL) {\r
+    return 0;\r
+  }\r
   Failure[0]  = -1;\r
   for (j = 1; j < Lenp; j++) {\r
     i = Failure[j - 1];\r
   Failure[0]  = -1;\r
   for (j = 1; j < Lenp; j++) {\r
     i = Failure[j - 1];\r
index 324db922e6ae6d5d6ee5b9830df9dba9c5552bac..afccf7bd5821aa0a7740ae73225e5fb87387a1c5 100644 (file)
@@ -154,11 +154,15 @@ ShellCommandRunSetVar (
             // arbitrary buffer\r
             //\r
             Buffer = AllocateZeroPool((StrLen(Data) / 2));\r
             // arbitrary buffer\r
             //\r
             Buffer = AllocateZeroPool((StrLen(Data) / 2));\r
-            for (LoopVar = 0 ; LoopVar < (StrLen(Data) / 2) ; LoopVar++) {\r
-              ((UINT8*)Buffer)[LoopVar] = (UINT8)(HexCharToUintn(Data[LoopVar*2]) * 16);\r
-              ((UINT8*)Buffer)[LoopVar] = (UINT8)(((UINT8*)Buffer)[LoopVar] + HexCharToUintn(Data[LoopVar*2+1]));\r
+            if (Buffer == NULL) {\r
+              Status = EFI_OUT_OF_RESOURCES;\r
+            } else {\r
+              for (LoopVar = 0 ; LoopVar < (StrLen(Data) / 2) ; LoopVar++) {\r
+                ((UINT8*)Buffer)[LoopVar] = (UINT8)(HexCharToUintn(Data[LoopVar*2]) * 16);\r
+                ((UINT8*)Buffer)[LoopVar] = (UINT8)(((UINT8*)Buffer)[LoopVar] + HexCharToUintn(Data[LoopVar*2+1]));\r
+              }\r
+              Status = gRT->SetVariable((CHAR16*)VariableName, &Guid, Attributes, StrLen(Data) / 2, Buffer);\r
             }\r
             }\r
-            Status = gRT->SetVariable((CHAR16*)VariableName, &Guid, Attributes, StrLen(Data) / 2, Buffer);\r
             if (EFI_ERROR(Status)) {\r
               ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SETVAR_ERROR_SET), gShellDebug1HiiHandle, &Guid, VariableName, Status);\r
               ShellStatus = SHELL_ACCESS_DENIED;\r
             if (EFI_ERROR(Status)) {\r
               ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SETVAR_ERROR_SET), gShellDebug1HiiHandle, &Guid, VariableName, Status);\r
               ShellStatus = SHELL_ACCESS_DENIED;\r
@@ -181,11 +185,13 @@ ShellCommandRunSetVar (
           //\r
           Data++;\r
           Buffer = AllocateZeroPool(StrSize(Data) / 2);\r
           //\r
           Data++;\r
           Buffer = AllocateZeroPool(StrSize(Data) / 2);\r
-          AsciiSPrint(Buffer, StrSize(Data) / 2, "%s", Data);\r
-          ((CHAR8*)Buffer)[AsciiStrLen(Buffer)-1] = CHAR_NULL;\r
-\r
-          \r
-          Status = gRT->SetVariable((CHAR16*)VariableName, &Guid, Attributes, AsciiStrSize(Buffer)-sizeof(CHAR8), Buffer);\r
+          if (Buffer == NULL) {\r
+            Status = EFI_OUT_OF_RESOURCES;\r
+          } else {\r
+            AsciiSPrint(Buffer, StrSize(Data) / 2, "%s", Data);\r
+            ((CHAR8*)Buffer)[AsciiStrLen(Buffer)-1] = CHAR_NULL;\r
+            Status = gRT->SetVariable((CHAR16*)VariableName, &Guid, Attributes, AsciiStrSize(Buffer)-sizeof(CHAR8), Buffer);\r
+          }\r
           if (EFI_ERROR(Status)) {\r
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SETVAR_ERROR_SET), gShellDebug1HiiHandle, &Guid, VariableName, Status);\r
             ShellStatus = SHELL_ACCESS_DENIED;\r
           if (EFI_ERROR(Status)) {\r
             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SETVAR_ERROR_SET), gShellDebug1HiiHandle, &Guid, VariableName, Status);\r
             ShellStatus = SHELL_ACCESS_DENIED;\r
index f0a9d54b7397a2675199d00d2183dd27688673d3..a1e14678f34271cbe3bb19d02e9977a421608e4c 100644 (file)
@@ -340,55 +340,56 @@ DisplaySysEventLogData (
   //\r
   Offset  = 0;\r
   Log     = (LOG_RECORD_FORMAT *) LogData;\r
   //\r
   Offset  = 0;\r
   Log     = (LOG_RECORD_FORMAT *) LogData;\r
-  while (Log->Type != END_OF_LOG && Offset < LogAreaLength) {\r
+  while (Log != NULL && Log->Type != END_OF_LOG && Offset < LogAreaLength) {\r
     //\r
     // Get a Event Log Record\r
     //\r
     Log = (LOG_RECORD_FORMAT *) (LogData + Offset);\r
 \r
     //\r
     // Get a Event Log Record\r
     //\r
     Log = (LOG_RECORD_FORMAT *) (LogData + Offset);\r
 \r
-    //\r
-    // Display Event Log Record Information\r
-    //\r
-    DisplaySELVarDataFormatType (Log->Type, SHOW_DETAIL);\r
-    DisplaySELLogHeaderLen (Log->Length, SHOW_DETAIL);\r
-\r
-    Offset += Log->Length;\r
-\r
-    //\r
-    // Display Log Header Date/Time Fields\r
-    // These fields contain the BCD representation of the date and time\r
-    // (as read from CMOS) of the occurrence of the event\r
-    // So Print as hex and represent decimal\r
-    //\r
-    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_EVENTLOGINFO_DATE), gShellDebug1HiiHandle);\r
-    if (Log != NULL && Log->Year >= 80 && Log->Year <= 99) {\r
-      Print (L"19");\r
-    } else if (Log != NULL && Log->Year <= 79) {\r
-      Print (L"20");\r
-    } else {\r
-      ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_EVENTLOGINFO_ERROR), gShellDebug1HiiHandle);\r
-      continue;\r
+    if (Log != NULL) {\r
+      //\r
+      // Display Event Log Record Information\r
+      //\r
+      DisplaySELVarDataFormatType (Log->Type, SHOW_DETAIL);\r
+      DisplaySELLogHeaderLen (Log->Length, SHOW_DETAIL);\r
+\r
+      Offset += Log->Length;\r
+      //\r
+      // Display Log Header Date/Time Fields\r
+      // These fields contain the BCD representation of the date and time\r
+      // (as read from CMOS) of the occurrence of the event\r
+      // So Print as hex and represent decimal\r
+      //\r
+      ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_EVENTLOGINFO_DATE), gShellDebug1HiiHandle);\r
+      if (Log != NULL && Log->Year >= 80 && Log->Year <= 99) {\r
+        Print (L"19");\r
+      } else if (Log != NULL && Log->Year <= 79) {\r
+        Print (L"20");\r
+      } else {\r
+        ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_EVENTLOGINFO_ERROR), gShellDebug1HiiHandle);\r
+        continue;\r
+      }\r
+\r
+      ShellPrintHiiEx(-1,-1,NULL,\r
+        STRING_TOKEN (STR_SMBIOSVIEW_EVENTLOGINFO_TIME_SIX_VARS),\r
+        gShellDebug1HiiHandle,\r
+        Log->Year,\r
+        Log->Month,\r
+        Log->Day,\r
+        Log->Hour,\r
+        Log->Minute,\r
+        Log->Second\r
+       );\r
+\r
+      //\r
+      // Display Variable Data Format\r
+      //\r
+      if (Log->Length <= (sizeof (LOG_RECORD_FORMAT) - 1)) {\r
+        continue;\r
+      }\r
+\r
+      ElVdfType = Log->LogVariableData[0];\r
+      DisplayElVdfInfo (ElVdfType, Log->LogVariableData);\r
     }\r
     }\r
-\r
-    ShellPrintHiiEx(-1,-1,NULL,\r
-      STRING_TOKEN (STR_SMBIOSVIEW_EVENTLOGINFO_TIME_SIX_VARS),\r
-      gShellDebug1HiiHandle,\r
-      Log->Year,\r
-      Log->Month,\r
-      Log->Day,\r
-      Log->Hour,\r
-      Log->Minute,\r
-      Log->Second\r
-     );\r
-\r
-    //\r
-    // Display Variable Data Format\r
-    //\r
-    if (Log->Length <= (sizeof (LOG_RECORD_FORMAT) - 1)) {\r
-      continue;\r
-    }\r
-\r
-    ElVdfType = Log->LogVariableData[0];\r
-    DisplayElVdfInfo (ElVdfType, Log->LogVariableData);\r
   }\r
 }\r
   }\r
 }\r
index c04dba5b7652534cc6ff59a12a98f370cf9e287c..7b7e5928bd204923a96cbf3740e773bcffcc67a7 100644 (file)
@@ -2,7 +2,7 @@
   Build a table, each item is (Key, Info) pair.\r
   And give a interface of query a string out of a table.\r
 \r
   Build a table, each item is (Key, Info) pair.\r
   And give a interface of query a string out of a table.\r
 \r
-  Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2005 - 2011, 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
   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
@@ -2921,27 +2921,8 @@ TABLE_ITEM  StructureTypeInfoTable[] = {
 };\r
 \r
 \r
 };\r
 \r
 \r
-UINT8\r
-QueryTable (\r
-  IN  TABLE_ITEM    *Table,\r
-  IN  UINTN         Number,\r
-  IN  UINT8         Key,\r
-  IN  OUT CHAR16    *Info\r
-  )\r
-/*++\r
-Routine Description:\r
-  Function Description\r
-    Given a table and a Key, return the responding info.\r
-\r
-  Arguments:\r
-    Table   -  The begin address of table\r
-    Number  -  The number of table items\r
-    Key     -  The query Key\r
-    Info    -  Input as empty buffer; output as data buffer.\r
-\r
-  Returns:\r
-    if Key found   - return found Key and Info\r
-    if Key unfound - return QUERY_TABLE_UNFOUND, Info=NULL\r
+/**\r
+  Given a table and a Key, return the responding info.\r
 \r
   Notes:\r
     Table[Index].Key is change from UINT8 to UINT16,\r
 \r
   Notes:\r
     Table[Index].Key is change from UINT8 to UINT16,\r
@@ -2955,7 +2936,23 @@ Routine Description:
     Then all the Key Value between Low and High gets the same string\r
     L"Unused".\r
 \r
     Then all the Key Value between Low and High gets the same string\r
     L"Unused".\r
 \r
+  @param[in] Table    The begin address of table.\r
+  @param[in] Number   The number of table items.\r
+  @param[in] Key      The query Key.\r
+  @param[in,out] Info Input as empty buffer; output as data buffer.\r
+  @param[in] InfoLen  The max number of characters for Info.\r
+\r
+  @return the found Key and Info is valid.\r
+  @retval QUERY_TABLE_UNFOUND and Info should be NULL.\r
 **/\r
 **/\r
+UINT8\r
+QueryTable (\r
+  IN  TABLE_ITEM    *Table,\r
+  IN  UINTN         Number,\r
+  IN  UINT8         Key,\r
+  IN  OUT CHAR16    *Info,\r
+  IN  UINTN         InfoLen\r
+  )\r
 {\r
   UINTN Index;\r
   //\r
 {\r
   UINTN Index;\r
   //\r
@@ -2971,7 +2968,7 @@ Routine Description:
     // Check if Key is in the range\r
     //\r
     if (High > Low && Key >= Low && Key <= High) {\r
     // Check if Key is in the range\r
     //\r
     if (High > Low && Key >= Low && Key <= High) {\r
-      StrCpy (Info, Table[Index].Info);\r
+      StrnCpy (Info, Table[Index].Info, InfoLen-1);\r
       StrCat (Info, L"\n");\r
       return Key;\r
     }\r
       StrCat (Info, L"\n");\r
       return Key;\r
     }\r
@@ -2979,13 +2976,13 @@ Routine Description:
     // Check if Key == Value in the table\r
     //\r
     if (Table[Index].Key == Key) {\r
     // Check if Key == Value in the table\r
     //\r
     if (Table[Index].Key == Key) {\r
-      StrCpy (Info, Table[Index].Info);\r
+      StrnCpy (Info, Table[Index].Info, InfoLen-1);\r
       StrCat (Info, L"\n");\r
       return Key;\r
     }\r
   }\r
 \r
       StrCat (Info, L"\n");\r
       return Key;\r
     }\r
   }\r
 \r
-  StrCpy (Info, L"Undefined Value\n");\r
+  StrnCpy (Info, L"Undefined Value\n", InfoLen);\r
   return QUERY_TABLE_UNFOUND;\r
 }\r
 \r
   return QUERY_TABLE_UNFOUND;\r
 }\r
 \r
@@ -3069,7 +3066,7 @@ PrintBitsInfo (
     CHAR16  Info[66]; \\r
     Num = sizeof (Table) / sizeof (TABLE_ITEM); \\r
     ZeroMem (Info, sizeof (Info)); \\r
     CHAR16  Info[66]; \\r
     Num = sizeof (Table) / sizeof (TABLE_ITEM); \\r
     ZeroMem (Info, sizeof (Info)); \\r
-    QueryTable (Table, Num, Key, Info); \\r
+    QueryTable (Table, Num, Key, Info, sizeof(Info)/sizeof(Info[0])); \\r
     Print (Info); \\r
   } while (0);\r
 \r
     Print (Info); \\r
   } while (0);\r
 \r
index adacc41cf3cd50e9b47c7a39f4d340ac6c31a5e0..1022132f1046234fa2e79615ade8719c58378caa 100644 (file)
@@ -2,7 +2,7 @@
   Build a table, each item is (key, info) pair.\r
   and give a interface of query a string out of a table.\r
 \r
   Build a table, each item is (key, info) pair.\r
   and give a interface of query a string out of a table.\r
 \r
-  Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2005 - 2011, 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
   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
@@ -37,12 +37,37 @@ typedef struct TABLE_ITEM {
     } \\r
   } while (0);\r
 \r
     } \\r
   } while (0);\r
 \r
+/**\r
+  Given a table and a Key, return the responding info.\r
+\r
+  Notes:\r
+    Table[Index].Key is change from UINT8 to UINT16,\r
+    in order to deal with "0xaa - 0xbb".\r
+\r
+    For example:\r
+      DisplaySELVariableDataFormatTypes(UINT8 Type, UINT8 Option)\r
+    has a item:\r
+      "0x07-0x7F,   Unused"\r
+    Now define Key = 0x7F07, that is to say: High = 0x7F, Low = 0x07.\r
+    Then all the Key Value between Low and High gets the same string\r
+    L"Unused".\r
+\r
+  @param[in] Table    The begin address of table.\r
+  @param[in] Number   The number of table items.\r
+  @param[in] Key      The query Key.\r
+  @param[in,out] Info Input as empty buffer; output as data buffer.\r
+  @param[in] InfoLen  The max number of characters for Info.\r
+\r
+  @return the found Key and Info is valid.\r
+  @retval QUERY_TABLE_UNFOUND and Info should be NULL.\r
+**/\r
 UINT8\r
 QueryTable (\r
   IN  TABLE_ITEM    *Table,\r
   IN  UINTN         Number,\r
   IN  UINT8         Key,\r
 UINT8\r
 QueryTable (\r
   IN  TABLE_ITEM    *Table,\r
   IN  UINTN         Number,\r
   IN  UINT8         Key,\r
-  IN  OUT CHAR16    *Info\r
+  IN  OUT CHAR16    *Info,\r
+  IN  UINTN         InfoLen\r
   );\r
 \r
 VOID\r
   );\r
 \r
 VOID\r
index 226dd903971a794e43309e80ddfeb352ddd1b68f..cccec126b4d9dc20be22752c3a706d9e53daa04a 100644 (file)
@@ -310,7 +310,9 @@ ConvertStringToGuid (
   TempCopy = StrnCatGrow(&TempCopy, NULL, StringGuid, 0);\r
   Walker   = TempCopy;\r
   TempSpot = StrStr(Walker, L"-");\r
   TempCopy = StrnCatGrow(&TempCopy, NULL, StringGuid, 0);\r
   Walker   = TempCopy;\r
   TempSpot = StrStr(Walker, L"-");\r
-  *TempSpot = CHAR_NULL;\r
+  if (TempSpot != NULL) {\r
+    *TempSpot = CHAR_NULL;\r
+  }\r
   Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
   if (EFI_ERROR(Status)) {\r
     FreePool(TempCopy);\r
   Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
   if (EFI_ERROR(Status)) {\r
     FreePool(TempCopy);\r
@@ -319,7 +321,9 @@ ConvertStringToGuid (
   Guid->Data1 = (UINT32)TempVal;\r
   Walker += 9;\r
   TempSpot = StrStr(Walker, L"-");\r
   Guid->Data1 = (UINT32)TempVal;\r
   Walker += 9;\r
   TempSpot = StrStr(Walker, L"-");\r
-  *TempSpot = CHAR_NULL;\r
+  if (TempSpot != NULL) {\r
+    *TempSpot = CHAR_NULL;\r
+  }\r
   Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
   if (EFI_ERROR(Status)) {\r
     FreePool(TempCopy);\r
   Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
   if (EFI_ERROR(Status)) {\r
     FreePool(TempCopy);\r
@@ -328,7 +332,9 @@ ConvertStringToGuid (
   Guid->Data2 = (UINT16)TempVal;\r
   Walker += 5;\r
   TempSpot = StrStr(Walker, L"-");\r
   Guid->Data2 = (UINT16)TempVal;\r
   Walker += 5;\r
   TempSpot = StrStr(Walker, L"-");\r
-  *TempSpot = CHAR_NULL;\r
+  if (TempSpot != NULL) {\r
+    *TempSpot = CHAR_NULL;\r
+  }\r
   Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
   if (EFI_ERROR(Status)) {\r
     FreePool(TempCopy);\r
   Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
   if (EFI_ERROR(Status)) {\r
     FreePool(TempCopy);\r
index f5a228665787cefb97999b012c4bd0d692df676a..ec03df1d60413aff51aeea2b37ea94da388a6ec2 100644 (file)
@@ -265,27 +265,31 @@ BcfgAddInstall1(
     FilePathSize = GetDevicePathSize (FilePath);\r
 \r
     TempByteBuffer = AllocateZeroPool(sizeof(UINT32) + sizeof(UINT16) + DescSize + FilePathSize);\r
     FilePathSize = GetDevicePathSize (FilePath);\r
 \r
     TempByteBuffer = AllocateZeroPool(sizeof(UINT32) + sizeof(UINT16) + DescSize + FilePathSize);\r
-    TempByteStart  = TempByteBuffer;\r
-    *((UINT32 *) TempByteBuffer) = LOAD_OPTION_ACTIVE;      // Attributes\r
-    TempByteBuffer += sizeof (UINT32);\r
+    if (TempByteBuffer != NULL) {\r
+      TempByteStart  = TempByteBuffer;\r
+      *((UINT32 *) TempByteBuffer) = LOAD_OPTION_ACTIVE;      // Attributes\r
+      TempByteBuffer += sizeof (UINT32);\r
 \r
 \r
-    *((UINT16 *) TempByteBuffer) = (UINT16)FilePathSize;    // FilePathListLength\r
-    TempByteBuffer += sizeof (UINT16);\r
+      *((UINT16 *) TempByteBuffer) = (UINT16)FilePathSize;    // FilePathListLength\r
+      TempByteBuffer += sizeof (UINT16);\r
 \r
 \r
-    CopyMem (TempByteBuffer, Desc, DescSize);\r
-    TempByteBuffer += DescSize;\r
-    CopyMem (TempByteBuffer, FilePath, FilePathSize);\r
+      CopyMem (TempByteBuffer, Desc, DescSize);\r
+      TempByteBuffer += DescSize;\r
+      CopyMem (TempByteBuffer, FilePath, FilePathSize);\r
 \r
 \r
-    UnicodeSPrint (OptionStr, sizeof(OptionStr), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", TargetLocation);\r
-    Status = gRT->SetVariable (\r
-          OptionStr,\r
-          &gEfiGlobalVariableGuid,\r
-          EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,\r
-          sizeof(UINT32) + sizeof(UINT16) + DescSize + FilePathSize,\r
-          TempByteStart\r
-         );\r
-\r
-    FreePool(TempByteStart);\r
+      UnicodeSPrint (OptionStr, sizeof(OptionStr), L"%s%04x", Target == BcfgTargetBootOrder?L"Boot":L"Driver", TargetLocation);\r
+      Status = gRT->SetVariable (\r
+            OptionStr,\r
+            &gEfiGlobalVariableGuid,\r
+            EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,\r
+            sizeof(UINT32) + sizeof(UINT16) + DescSize + FilePathSize,\r
+            TempByteStart\r
+           );\r
+\r
+      FreePool(TempByteStart);\r
+    } else {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+    }\r
 \r
     if (EFI_ERROR(Status)) {\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellInstall1HiiHandle, OptionStr, Status);\r
 \r
     if (EFI_ERROR(Status)) {\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_SET_VAR_FAIL), gShellInstall1HiiHandle, OptionStr, Status);\r
@@ -385,22 +389,25 @@ BcfgRemoveInstall1(
     return (SHELL_INVALID_PARAMETER);\r
   }\r
   NewOrder = AllocateZeroPool(OrderCount*sizeof(CurrentOrder[0]));\r
     return (SHELL_INVALID_PARAMETER);\r
   }\r
   NewOrder = AllocateZeroPool(OrderCount*sizeof(CurrentOrder[0]));\r
-  NewCount = OrderCount;\r
-  CopyMem(NewOrder, CurrentOrder, OrderCount*sizeof(CurrentOrder[0]));\r
-  for (LoopVar = 0 ; LoopVar < OrderCount ; LoopVar++){\r
-    if (NewOrder[LoopVar] == Location) {\r
-      CopyMem(NewOrder+LoopVar, NewOrder+LoopVar+1, (OrderCount - LoopVar - 1)*sizeof(CurrentOrder[0]));\r
-      NewCount--;\r
+  if (NewOrder != NULL) {\r
+    NewCount = OrderCount;\r
+    CopyMem(NewOrder, CurrentOrder, OrderCount*sizeof(CurrentOrder[0]));\r
+    for (LoopVar = 0 ; LoopVar < OrderCount ; LoopVar++){\r
+      if (NewOrder[LoopVar] == Location) {\r
+        CopyMem(NewOrder+LoopVar, NewOrder+LoopVar+1, (OrderCount - LoopVar - 1)*sizeof(CurrentOrder[0]));\r
+        NewCount--;\r
+      }\r
     }\r
     }\r
+    Status = gRT->SetVariable(\r
+      Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",\r
+      (EFI_GUID*)&gEfiGlobalVariableGuid,\r
+      EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,\r
+      NewCount*sizeof(NewOrder[0]),\r
+      NewOrder);\r
+    FreePool(NewOrder);\r
+  } else {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
   }\r
   }\r
-  Status = gRT->SetVariable(\r
-    Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",\r
-    (EFI_GUID*)&gEfiGlobalVariableGuid,\r
-    EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS,\r
-    NewCount*sizeof(NewOrder[0]),\r
-    NewOrder);\r
-  FreePool(NewOrder);\r
-\r
   if (EFI_ERROR(Status)) {\r
     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellInstall1HiiHandle, Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder", Status);\r
     return (SHELL_INVALID_PARAMETER);\r
   if (EFI_ERROR(Status)) {\r
     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_BCFG_WRITE_FAIL), gShellInstall1HiiHandle, Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder", Status);\r
     return (SHELL_INVALID_PARAMETER);\r
index 006ce6c67599bd944a07001eb512ce4eac8582ea..ddcfd45de381cbb375db39daf08babe2f56453c2 100644 (file)
@@ -86,7 +86,17 @@ ShellCommandRunEndFor (
   Found = MoveToTag(GetPreviousNode, L"for", L"endfor", NULL, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, FALSE);\r
 \r
   if (!Found) {\r
   Found = MoveToTag(GetPreviousNode, L"for", L"endfor", NULL, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, FALSE);\r
 \r
   if (!Found) {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"For", L"EndFor", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);\r
+    ShellPrintHiiEx(\r
+      -1, \r
+      -1, \r
+      NULL, \r
+      STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r
+      gShellLevel1HiiHandle, \r
+      L"For", \r
+      L"EndFor", \r
+      ShellCommandGetCurrentScriptFile()!=NULL\r
+        &&ShellCommandGetCurrentScriptFile()->CurrentCommand!=NULL\r
+          ?ShellCommandGetCurrentScriptFile()->CurrentCommand->Line:0);\r
     return (SHELL_NOT_FOUND);\r
   }\r
   return (SHELL_SUCCESS);\r
     return (SHELL_NOT_FOUND);\r
   }\r
   return (SHELL_SUCCESS);\r
@@ -305,7 +315,16 @@ ShellCommandRunFor (
     // Make sure that an End exists.\r
     //\r
     if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, TRUE, FALSE)) {\r
     // Make sure that an End exists.\r
     //\r
     if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, TRUE, FALSE)) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"EndFor", L"For", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);\r
+      ShellPrintHiiEx(\r
+        -1, \r
+        -1, \r
+        NULL, \r
+        STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r
+        gShellLevel1HiiHandle, \r
+        L"EndFor", \r
+        L"For", \r
+        CurrentScriptFile->CurrentCommand!=NULL\r
+          ?CurrentScriptFile->CurrentCommand->Line:0);\r
       return (SHELL_DEVICE_ERROR);\r
     }\r
 \r
       return (SHELL_DEVICE_ERROR);\r
     }\r
 \r
index 8213fae7ac27b23803d15f8463ce195716277d08..3e5a59c5756019d325cbca3d4c8f3a27f00960b3 100644 (file)
@@ -79,7 +79,17 @@ ShellCommandRunGoto (
       // Check forwards and then backwards for a label...\r
       //\r
       if (!MoveToTag(GetNextNode, L"endfor", L"for", CompareString, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, TRUE)) {\r
       // Check forwards and then backwards for a label...\r
       //\r
       if (!MoveToTag(GetNextNode, L"endfor", L"for", CompareString, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, TRUE)) {\r
-        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, CompareString, L"Goto", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);\r
+        ShellPrintHiiEx(\r
+          -1, \r
+          -1, \r
+          NULL, \r
+          STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r
+          gShellLevel1HiiHandle, \r
+          CompareString, \r
+          L"Goto", \r
+          ShellCommandGetCurrentScriptFile()!=NULL\r
+            &&ShellCommandGetCurrentScriptFile()->CurrentCommand!=NULL\r
+              ?ShellCommandGetCurrentScriptFile()->CurrentCommand->Line:0);\r
         ShellStatus = SHELL_NOT_FOUND;\r
       }\r
     FreePool(CompareString);\r
         ShellStatus = SHELL_NOT_FOUND;\r
       }\r
     FreePool(CompareString);\r
index 59069e568f42d09565d005f73c85c046977bc595..a3c4482bb3bfc3284347a7deba775f65e1ee3f0c 100644 (file)
@@ -844,7 +844,17 @@ ShellCommandRunIf (
   // Make sure that an End exists.\r
   //\r
   if (!MoveToTag(GetNextNode, L"endif", L"if", NULL, ShellCommandGetCurrentScriptFile(), TRUE, TRUE, FALSE)) {\r
   // Make sure that an End exists.\r
   //\r
   if (!MoveToTag(GetNextNode, L"endif", L"if", NULL, ShellCommandGetCurrentScriptFile(), TRUE, TRUE, FALSE)) {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"EnfIf", L"If", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);\r
+    ShellPrintHiiEx(\r
+      -1, \r
+      -1, \r
+      NULL, \r
+      STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r
+      gShellLevel1HiiHandle, \r
+      L"EnfIf", \r
+      L"If", \r
+      ShellCommandGetCurrentScriptFile()!=NULL\r
+        &&ShellCommandGetCurrentScriptFile()->CurrentCommand!=NULL\r
+          ?ShellCommandGetCurrentScriptFile()->CurrentCommand->Line:0);\r
     return (SHELL_DEVICE_ERROR);\r
   }\r
 \r
     return (SHELL_DEVICE_ERROR);\r
   }\r
 \r
@@ -983,16 +993,46 @@ ShellCommandRunElse (
 \r
 \r
   if (!MoveToTag(GetPreviousNode, L"if", L"endif", NULL, ShellCommandGetCurrentScriptFile(), FALSE, TRUE, FALSE)) {\r
 \r
 \r
   if (!MoveToTag(GetPreviousNode, L"if", L"endif", NULL, ShellCommandGetCurrentScriptFile(), FALSE, TRUE, FALSE)) {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"If", L"Else", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);\r
+    ShellPrintHiiEx(\r
+      -1, \r
+      -1, \r
+      NULL, \r
+      STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r
+      gShellLevel1HiiHandle, \r
+      L"If", \r
+      L"Else", \r
+      ShellCommandGetCurrentScriptFile()!=NULL\r
+        &&ShellCommandGetCurrentScriptFile()->CurrentCommand!=NULL\r
+          ?ShellCommandGetCurrentScriptFile()->CurrentCommand->Line:0);\r
     return (SHELL_DEVICE_ERROR);\r
   }\r
   if (!MoveToTag(GetPreviousNode, L"if", L"else", NULL, ShellCommandGetCurrentScriptFile(), FALSE, TRUE, FALSE)) {\r
     return (SHELL_DEVICE_ERROR);\r
   }\r
   if (!MoveToTag(GetPreviousNode, L"if", L"else", NULL, ShellCommandGetCurrentScriptFile(), FALSE, TRUE, FALSE)) {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"If", L"Else", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);\r
+    ShellPrintHiiEx(\r
+      -1, \r
+      -1, \r
+      NULL, \r
+      STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r
+      gShellLevel1HiiHandle, \r
+      L"If", \r
+      L"Else", \r
+      ShellCommandGetCurrentScriptFile()!=NULL\r
+        &&ShellCommandGetCurrentScriptFile()->CurrentCommand!=NULL\r
+          ?ShellCommandGetCurrentScriptFile()->CurrentCommand->Line:0);\r
     return (SHELL_DEVICE_ERROR);\r
   }\r
 \r
   if (!MoveToTag(GetNextNode, L"endif", L"if", NULL, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, FALSE)) {\r
     return (SHELL_DEVICE_ERROR);\r
   }\r
 \r
   if (!MoveToTag(GetNextNode, L"endif", L"if", NULL, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, FALSE)) {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"EndIf", "Else", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);\r
+    ShellPrintHiiEx(\r
+      -1, \r
+      -1, \r
+      NULL, \r
+      STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r
+      gShellLevel1HiiHandle, \r
+      L"EndIf", \r
+      "Else", \r
+      ShellCommandGetCurrentScriptFile()!=NULL\r
+        &&ShellCommandGetCurrentScriptFile()->CurrentCommand!=NULL\r
+          ?ShellCommandGetCurrentScriptFile()->CurrentCommand->Line:0);\r
     return (SHELL_DEVICE_ERROR);\r
   }\r
 \r
     return (SHELL_DEVICE_ERROR);\r
   }\r
 \r
@@ -1025,7 +1065,17 @@ ShellCommandRunEndIf (
   }\r
 \r
   if (!MoveToTag(GetPreviousNode, L"if", L"endif", NULL, ShellCommandGetCurrentScriptFile(), FALSE, TRUE, FALSE)) {\r
   }\r
 \r
   if (!MoveToTag(GetPreviousNode, L"if", L"endif", NULL, ShellCommandGetCurrentScriptFile(), FALSE, TRUE, FALSE)) {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"If", L"EndIf", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line);\r
+    ShellPrintHiiEx(\r
+      -1, \r
+      -1, \r
+      NULL, \r
+      STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r
+      gShellLevel1HiiHandle, \r
+      L"If", \r
+      L"EndIf", \r
+      ShellCommandGetCurrentScriptFile()!=NULL\r
+        &&ShellCommandGetCurrentScriptFile()->CurrentCommand!=NULL\r
+          ?ShellCommandGetCurrentScriptFile()->CurrentCommand->Line:0);\r
     return (SHELL_DEVICE_ERROR);\r
   }\r
 \r
     return (SHELL_DEVICE_ERROR);\r
   }\r
 \r
index 2b608a02cf620d97a02f72d998456087aae6fd47..e7d19c9bed702c84d339c68265010282991aba3c 100644 (file)
@@ -330,6 +330,9 @@ MappingListHasType(
   //\r
   if (Specific != NULL) {\r
     NewSpecific = AllocateZeroPool(StrSize(Specific) + sizeof(CHAR16));\r
   //\r
   if (Specific != NULL) {\r
     NewSpecific = AllocateZeroPool(StrSize(Specific) + sizeof(CHAR16));\r
+    if (NewSpecific == NULL){\r
+      return FALSE;\r
+    }\r
     StrCpy(NewSpecific, Specific);\r
     if (NewSpecific[StrLen(NewSpecific)-1] != L':') {\r
       StrCat(NewSpecific, L":");\r
     StrCpy(NewSpecific, Specific);\r
     if (NewSpecific[StrLen(NewSpecific)-1] != L':') {\r
       StrCat(NewSpecific, L":");\r
@@ -609,7 +612,7 @@ PerformMappingDisplay(
   // Get the map name(s) for each one.\r
   //\r
   for ( LoopVar = 0, Found = FALSE\r
   // Get the map name(s) for each one.\r
   //\r
   for ( LoopVar = 0, Found = FALSE\r
-      ; LoopVar < (BufferSize / sizeof(EFI_HANDLE))\r
+      ; LoopVar < (BufferSize / sizeof(EFI_HANDLE)) && HandleBuffer != NULL\r
       ; LoopVar ++\r
      ){\r
     Status = PerformSingleMappingDisplay(\r
       ; LoopVar ++\r
      ){\r
     Status = PerformSingleMappingDisplay(\r
@@ -635,7 +638,7 @@ PerformMappingDisplay(
     &BufferSize,\r
     HandleBuffer);\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
     &BufferSize,\r
     HandleBuffer);\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    FreePool(HandleBuffer);\r
+    SHELL_FREE_NON_NULL(HandleBuffer);\r
     HandleBuffer = AllocateZeroPool(BufferSize);\r
     if (HandleBuffer == NULL) {\r
       return (SHELL_OUT_OF_RESOURCES);\r
     HandleBuffer = AllocateZeroPool(BufferSize);\r
     if (HandleBuffer == NULL) {\r
       return (SHELL_OUT_OF_RESOURCES);\r
@@ -897,6 +900,9 @@ AddMappingFromMapping(
   CHAR16                          *NewSName;\r
   \r
   NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));\r
   CHAR16                          *NewSName;\r
   \r
   NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));\r
+  if (NewSName == NULL) {\r
+    return (SHELL_OUT_OF_RESOURCES);\r
+  }\r
   StrCpy(NewSName, SName);\r
   if (NewSName[StrLen(NewSName)-1] != L':') {\r
     StrCat(NewSName, L":");\r
   StrCpy(NewSName, SName);\r
   if (NewSName[StrLen(NewSName)-1] != L':') {\r
     StrCat(NewSName, L":");\r
@@ -947,6 +953,9 @@ AddMappingFromHandle(
   CHAR16                    *NewSName;\r
   \r
   NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));\r
   CHAR16                    *NewSName;\r
   \r
   NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));\r
+  if (NewSName == NULL) {\r
+    return (SHELL_OUT_OF_RESOURCES);\r
+  }\r
   StrCpy(NewSName, SName);\r
   if (NewSName[StrLen(NewSName)-1] != L':') {\r
     StrCat(NewSName, L":");\r
   StrCpy(NewSName, SName);\r
   if (NewSName[StrLen(NewSName)-1] != L':') {\r
     StrCat(NewSName, L":");\r
index 115013a1e30027d73b07a23598aa05b3466c768e..780b39e2fd7cdd8183085b274df21c2fd6bbd70e 100644 (file)
@@ -124,7 +124,7 @@ CheckAndSetDate (
   if (Walker1 != NULL) {\r
     Walker = Walker1 + 1;\r
   }\r
   if (Walker1 != NULL) {\r
     Walker = Walker1 + 1;\r
   }\r
-  Walker1 = StrStr(Walker, L"/");\r
+  Walker1 = Walker!=NULL?StrStr(Walker, L"/"):NULL;\r
   if (Walker1 != NULL && *Walker1 == L'/') {\r
     *Walker1 = CHAR_NULL;\r
   }\r
   if (Walker1 != NULL && *Walker1 == L'/') {\r
     *Walker1 = CHAR_NULL;\r
   }\r
@@ -133,7 +133,7 @@ CheckAndSetDate (
     if (Walker1 != NULL) {\r
       Walker = Walker1 + 1;\r
     }\r
     if (Walker1 != NULL) {\r
       Walker = Walker1 + 1;\r
     }\r
-    Walker1 = StrStr(Walker, L"/");\r
+    Walker1 = Walker!=NULL?StrStr(Walker, L"/"):NULL;\r
     if (Walker1 != NULL && *Walker1 == L'/') {\r
       *Walker1 = CHAR_NULL;\r
     }\r
     if (Walker1 != NULL && *Walker1 == L'/') {\r
       *Walker1 = CHAR_NULL;\r
     }\r
@@ -312,7 +312,7 @@ CheckAndSetTime (
     TheTime.Hour    = 0xFF;\r
     TheTime.Minute  = 0xFF;\r
 \r
     TheTime.Hour    = 0xFF;\r
     TheTime.Minute  = 0xFF;\r
 \r
-    Walker2          = StrStr(Walker1, L":");\r
+    Walker2          = Walker1!=NULL?StrStr(Walker1, L":"):NULL;\r
     if (Walker2 != NULL && *Walker2 == L':') {\r
       *Walker2 = CHAR_NULL;\r
     }\r
     if (Walker2 != NULL && *Walker2 == L':') {\r
       *Walker2 = CHAR_NULL;\r
     }\r
@@ -320,7 +320,7 @@ CheckAndSetTime (
     if (Walker2 != NULL) {\r
       Walker1 = Walker2 + 1;\r
     }\r
     if (Walker2 != NULL) {\r
       Walker1 = Walker2 + 1;\r
     }\r
-    Walker2          = StrStr(Walker1, L":");\r
+    Walker2          = Walker1!=NULL?StrStr(Walker1, L":"):NULL;\r
     if (Walker2 != NULL && *Walker2 == L':') {\r
       *Walker2 = CHAR_NULL;\r
     }\r
     if (Walker2 != NULL && *Walker2 == L':') {\r
       *Walker2 = CHAR_NULL;\r
     }\r
index e9cd0d098244aff95dd0b63096a1ca2f26884068..53b7770dfe12073e9a2d05e1e5ac3f0d2ce43179 100644 (file)
@@ -97,6 +97,8 @@ HandleVol(
       SysInfo);\r
   }\r
 \r
       SysInfo);\r
   }\r
 \r
+  ASSERT(SysInfo != NULL);\r
+\r
   if (Delete) {\r
     StrCpy ((CHAR16 *) SysInfo->VolumeLabel, L"");\r
     SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize(SysInfo->VolumeLabel);\r
   if (Delete) {\r
     StrCpy ((CHAR16 *) SysInfo->VolumeLabel, L"");\r
     SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize(SysInfo->VolumeLabel);\r
index 94c9c021acf351122e558019faf014a0cb585d1b..3bfdf847dea2a59cc9b4050e7ec3fc559c6f1ff5 100644 (file)
@@ -606,13 +606,19 @@ IfconfigGetAllNicInfoByHii (
     // Construct configuration request string header\r
     //\r
     ConfigHdr = ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, ChildHandle);\r
     // Construct configuration request string header\r
     //\r
     ConfigHdr = ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, ChildHandle);\r
-    Length = StrLen (ConfigHdr);\r
+    if (ConfigHdr != NULL) {\r
+      Length = StrLen (ConfigHdr);\r
+    } else {\r
+      Length = 0;\r
+    }\r
     ConfigResp = AllocateZeroPool ((Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16));\r
     if (ConfigResp == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto ON_ERROR;\r
     }\r
     ConfigResp = AllocateZeroPool ((Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16));\r
     if (ConfigResp == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto ON_ERROR;\r
     }\r
-    StrCpy (ConfigResp, ConfigHdr);\r
+    if (ConfigHdr != NULL) {\r
+      StrCpy (ConfigResp, ConfigHdr);\r
+    }\r
  \r
     //\r
     // Append OFFSET/WIDTH pair\r
  \r
     //\r
     // Append OFFSET/WIDTH pair\r
@@ -772,10 +778,15 @@ IfconfigSetNicAddrByHii (
   // Construct config request string header\r
   //\r
   ConfigHdr = ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, ChildHandle);\r
   // Construct config request string header\r
   //\r
   ConfigHdr = ConstructConfigHdr (&gEfiNicIp4ConfigVariableGuid, EFI_NIC_IP4_CONFIG_VARIABLE, ChildHandle);\r
-\r
-  Length = StrLen (ConfigHdr);\r
+  if (ConfigHdr != NULL) {\r
+    Length = StrLen (ConfigHdr);\r
+  } else {\r
+    Length = 0;\r
+  }\r
   ConfigResp = AllocateZeroPool ((Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16));\r
   ConfigResp = AllocateZeroPool ((Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16));\r
-  StrCpy (ConfigResp, ConfigHdr);\r
+  if (ConfigHdr != NULL) {\r
+    StrCpy (ConfigResp, ConfigHdr);\r
+  }\r
 \r
   NicConfig = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);\r
   if (NicConfig == NULL) {\r
 \r
   NicConfig = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);\r
   if (NicConfig == NULL) {\r
index 493de26f8a95992543350c391ac475fb3eb06798..7982f99c579cb05b22e5c3299f81a0f79515ed47 100644 (file)
@@ -883,7 +883,7 @@ PingCreateIpInstance (
                   &HandleNum,\r
                   &HandleBuffer\r
                   );\r
                   &HandleNum,\r
                   &HandleBuffer\r
                   );\r
-  if (EFI_ERROR (Status) || (HandleNum == 0)) {\r
+  if (EFI_ERROR (Status) || (HandleNum == 0) || (HandleBuffer == NULL)) {\r
     return EFI_ABORTED;\r
   }\r
   //\r
     return EFI_ABORTED;\r
   }\r
   //\r