Index: Application/Shell/Shell.c
===================================================================
--- Application/Shell/Shell.c	(revision 15578)
+++ Application/Shell/Shell.c	(working copy)
@@ -509,6 +509,7 @@
           // Reset page break back to default.
           //
           ShellInfoObject.PageBreakEnabled        = PcdGetBool(PcdShellPageBreakDefault);
+          ASSERT (ShellInfoObject.ConsoleInfo != NULL);
           ShellInfoObject.ConsoleInfo->Enabled    = TRUE;
           ShellInfoObject.ConsoleInfo->RowCounter = 0;
 
@@ -2091,6 +2092,7 @@
   if (EFI_ERROR(Status)) {
     return (Status);
   }
+  ASSERT (*CmdLine != NULL);
 
   TrimSpaces(CmdLine);
 
Index: Application/Shell/ShellProtocol.c
===================================================================
--- Application/Shell/ShellProtocol.c	(revision 15578)
+++ Application/Shell/ShellProtocol.c	(working copy)
@@ -460,6 +460,7 @@
           ASSERT((PathForReturn == NULL && PathSize == 0) || (PathForReturn != NULL));
 
           AlignedNode = AllocateCopyPool (DevicePathNodeLength(FilePath), FilePath);
+          ASSERT (AlignedNode != NULL);
 
           // File Path Device Path Nodes 'can optionally add a "\" separator to
           //  the beginning and/or the end of the Path Name string.'
Index: Library/UefiShellDebug1CommandsLib/Bcfg.c
===================================================================
--- Library/UefiShellDebug1CommandsLib/Bcfg.c	(revision 15578)
+++ Library/UefiShellDebug1CommandsLib/Bcfg.c	(working copy)
@@ -1027,12 +1027,14 @@
         Buffer);
     if (Status == EFI_BUFFER_TOO_SMALL) {
       Buffer = AllocateZeroPool(BufferSize);
-      Status = gRT->GetVariable(
-          VariableName,
-          (EFI_GUID*)&gEfiGlobalVariableGuid,
-          NULL,
-          &BufferSize,
-          Buffer);
+      if (Buffer != NULL) {
+        Status = gRT->GetVariable(
+            VariableName,
+            (EFI_GUID*)&gEfiGlobalVariableGuid,
+            NULL,
+            &BufferSize,
+            Buffer);
+      }
     }
 
     if (EFI_ERROR(Status) || Buffer == NULL) {
@@ -1042,8 +1044,12 @@
 
     if ((*(UINT16*)(Buffer+4)) != 0) {
       DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4));
-      CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));
-      DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);
+      if (DevPath != NULL) {
+        CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));
+        DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);
+      } else {
+        DevPathString = NULL;
+      }
     } else {
       DevPath       = NULL;
       DevPathString = NULL;
@@ -1213,12 +1219,16 @@
         CurrentOperation.Order);
       if (Status == EFI_BUFFER_TOO_SMALL) {
         CurrentOperation.Order = AllocateZeroPool(Length+(4*sizeof(CurrentOperation.Order[0])));
-        Status = gRT->GetVariable(
-          CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
-          (EFI_GUID*)&gEfiGlobalVariableGuid,
-          NULL,
-          &Length,
-          CurrentOperation.Order);
+        if (CurrentOperation.Order != NULL) {
+          Status = gRT->GetVariable(
+            CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
+            (EFI_GUID*)&gEfiGlobalVariableGuid,
+            NULL,
+            &Length,
+            CurrentOperation.Order);
+        } else {
+          ShellStatus = SHELL_OUT_OF_RESOURCES;
+        }
       }
     }
 
Index: Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
===================================================================
--- Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c	(revision 15578)
+++ Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c	(working copy)
@@ -489,8 +489,9 @@
 
   CHAR16  *Buffer;
   UINTN   Limit;
-  CHAR16  PrintLine[200];
-  CHAR16  PrintLine2[250];
+  CHAR16  *PrintLine;
+  CHAR16  *PrintLine2;
+  UINTN   BufLen; 
 
   //
   // print start from correct character
@@ -502,14 +503,22 @@
     Limit = 0;
   }
 
-  StrnCpy (PrintLine, Buffer, MIN(MIN(Limit,MainEditor.ScreenSize.Column), 200));
+  BufLen = MainEditor.ScreenSize.Column + 1;
+  PrintLine = AllocatePool (BufLen);
+  ASSERT (PrintLine != NULL);
+
+  StrnCpy (PrintLine, Buffer, MIN(Limit, MainEditor.ScreenSize.Column));
   for (; Limit < MainEditor.ScreenSize.Column; Limit++) {
     PrintLine[Limit] = L' ';
   }
 
   PrintLine[MainEditor.ScreenSize.Column] = CHAR_NULL;
-  ShellCopySearchAndReplace(PrintLine, PrintLine2,  250, L"%", L"^%", FALSE, FALSE);
 
+  PrintLine2 = AllocatePool (BufLen * 2)
+  ASSERT (PrintLine2 != NULL);
+
+  ShellCopySearchAndReplace(PrintLine, PrintLine2, BufLen * 2, L"%", L"^%", FALSE, FALSE);
+
   ShellPrintEx (
     0,
     (INT32)Row - 1,
@@ -517,6 +526,9 @@
     PrintLine2
     );
 
+  FreePool (PrintLine);
+  FreePool (PrintLine2);
+
   return EFI_SUCCESS;
 }
 
Index: Library/UefiShellDebug1CommandsLib/Mm.c
===================================================================
--- Library/UefiShellDebug1CommandsLib/Mm.c	(revision 15578)
+++ Library/UefiShellDebug1CommandsLib/Mm.c	(working copy)
@@ -229,6 +229,7 @@
   SHELL_STATUS                    ShellStatus;
   CONST CHAR16                    *Temp;
 
+  Value         = 0;
   Address       = 0;
   PciEAddress   = 0;
   IoDev         = NULL;
Index: Library/UefiShellInstall1CommandsLib/Bcfg.c
===================================================================
--- Library/UefiShellInstall1CommandsLib/Bcfg.c	(revision 15578)
+++ Library/UefiShellInstall1CommandsLib/Bcfg.c	(working copy)
@@ -1040,8 +1040,12 @@
 
     if ((*(UINT16*)(Buffer+4)) != 0) {
       DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4));
-      CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));
-      DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);
+      if (DevPath == NULL) {
+        DevPathString = NULL;
+      } else {
+        CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));
+        DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);
+      }
     } else {
       DevPath       = NULL;
       DevPathString = NULL;
@@ -1211,12 +1215,16 @@
         CurrentOperation.Order);
       if (Status == EFI_BUFFER_TOO_SMALL) {
         CurrentOperation.Order = AllocateZeroPool(Length+(4*sizeof(CurrentOperation.Order[0])));
-        Status = gRT->GetVariable(
-          CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
-          (EFI_GUID*)&gEfiGlobalVariableGuid,
-          NULL,
-          &Length,
-          CurrentOperation.Order);
+        if (CurrentOperation.Order == NULL) {
+          ShellStatus = SHELL_OUT_OF_RESOURCES;
+        } else {
+          Status = gRT->GetVariable(
+            CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
+            (EFI_GUID*)&gEfiGlobalVariableGuid,
+            NULL,
+            &Length,
+            CurrentOperation.Order);
+        }
       }
     }
 
Index: Library/UefiShellLevel1CommandsLib/For.c
===================================================================
--- Library/UefiShellLevel1CommandsLib/For.c	(revision 15578)
+++ Library/UefiShellLevel1CommandsLib/For.c	(working copy)
@@ -333,7 +333,7 @@
   CurrentScriptFile = ShellCommandGetCurrentScriptFile();
   ASSERT(CurrentScriptFile != NULL);
 
-  if (CurrentScriptFile->CurrentCommand->Data == NULL) {
+  if ((CurrentScriptFile->CurrentCommand != NULL) && (CurrentScriptFile->CurrentCommand->Data == NULL)) {
     FirstPass = TRUE;
 
     //
@@ -348,8 +348,7 @@
         gShellLevel1HiiHandle, 
         L"EndFor", 
         L"For", 
-        CurrentScriptFile->CurrentCommand!=NULL
-          ?CurrentScriptFile->CurrentCommand->Line:0);
+        CurrentScriptFile->CurrentCommand->Line);
       return (SHELL_DEVICE_ERROR);
     }
 
@@ -459,9 +458,7 @@
             STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
             gShellLevel1HiiHandle, 
             ArgSet, 
-            CurrentScriptFile!=NULL 
-              && CurrentScriptFile->CurrentCommand!=NULL
-              ? CurrentScriptFile->CurrentCommand->Line:0);
+            CurrentScriptFile->CurrentCommand->Line);
           ShellStatus = SHELL_INVALID_PARAMETER;
         } else {
           TempSpot = StrStr(ArgSetWalker, L")");
@@ -483,9 +480,7 @@
               NULL, 
               STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
               gShellLevel1HiiHandle, 
-              CurrentScriptFile!=NULL 
-                && CurrentScriptFile->CurrentCommand!=NULL
-                ? CurrentScriptFile->CurrentCommand->Line:0);
+              CurrentScriptFile->CurrentCommand->Line);
             ShellStatus = SHELL_INVALID_PARAMETER;
           } else {
             *TempSpot = CHAR_NULL;
@@ -501,9 +496,7 @@
                 STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
                 gShellLevel1HiiHandle, 
                 ArgSet, 
-                CurrentScriptFile!=NULL 
-                  && CurrentScriptFile->CurrentCommand!=NULL
-                  ? CurrentScriptFile->CurrentCommand->Line:0);
+                CurrentScriptFile->CurrentCommand->Line);
               ShellStatus = SHELL_INVALID_PARAMETER;
             } else {
               if (ArgSetWalker[0] == L'-') {
@@ -523,9 +516,7 @@
                   STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
                   gShellLevel1HiiHandle, 
                   ArgSet, 
-                  CurrentScriptFile!=NULL 
-                    && CurrentScriptFile->CurrentCommand!=NULL
-                    ? CurrentScriptFile->CurrentCommand->Line:0);
+                  CurrentScriptFile->CurrentCommand->Line);
                 ShellStatus = SHELL_INVALID_PARAMETER;
               } else {
                 if (ArgSetWalker[0] == L'-') {
@@ -552,9 +543,7 @@
                       STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
                       gShellLevel1HiiHandle, 
                       ArgSet, 
-                      CurrentScriptFile!=NULL 
-                        && CurrentScriptFile->CurrentCommand!=NULL
-                        ? CurrentScriptFile->CurrentCommand->Line:0);
+                      CurrentScriptFile->CurrentCommand->Line);
                     ShellStatus = SHELL_INVALID_PARAMETER;
                   } else {
                     if (*ArgSetWalker == L')') {
@@ -574,9 +563,7 @@
                           STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
                           gShellLevel1HiiHandle, 
                           ArgSet, 
-                          CurrentScriptFile!=NULL 
-                            && CurrentScriptFile->CurrentCommand!=NULL
-                            ? CurrentScriptFile->CurrentCommand->Line:0);
+                          CurrentScriptFile->CurrentCommand->Line);
                         ShellStatus = SHELL_INVALID_PARAMETER;
                       }
                     }
