]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c
ShellPkg/for: Fix potential null pointer deference
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / HexEdit / BufferImage.c
index bfedf58d78a2dabe202138f960980c57b3a9cfd0..1048ecd41593a7d256ed187f88fbbaffd3493eb3 100644 (file)
@@ -2,7 +2,7 @@
   Defines HBufferImage - the view of the file that is visible at any point,\r
   as well as the event handlers for editing the file\r
   \r
-  Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2005 - 2017, 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
@@ -184,7 +184,7 @@ HBufferImageBackup (
   return EFI_SUCCESS;\r
 }\r
 \r
-/**
+/**\r
   Free all the lines in HBufferImage.\r
     Fields affected:\r
     Lines\r
@@ -318,9 +318,9 @@ HBufferImagePrintLine (
     }\r
 \r
     if (BeNewColor) {\r
-      gST->ConOut->SetAttribute (gST->ConOut, New.Data);\r
+      gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);\r
     } else {\r
-      gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
+      gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);\r
     }\r
 \r
     Pos = 10 + (Index * 3);\r
@@ -337,7 +337,7 @@ HBufferImagePrintLine (
 \r
   }\r
 \r
-  gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
+  gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);\r
   while (Index < 0x08) {\r
     Pos = 10 + (Index * 3);\r
     ShellPrintEx ((INT32)Pos - 1, (INT32)Row - 1, L"    ");\r
@@ -355,9 +355,9 @@ HBufferImagePrintLine (
     }\r
 \r
     if (BeNewColor) {\r
-      gST->ConOut->SetAttribute (gST->ConOut, New.Data);\r
+      gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);\r
     } else {\r
-      gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
+      gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);\r
     }\r
 \r
     Pos = 10 + (Index * 3) + 1;\r
@@ -370,7 +370,7 @@ HBufferImagePrintLine (
     Index++;\r
   }\r
 \r
-  gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
+  gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);\r
   while (Index < 0x10) {\r
     Pos = 10 + (Index * 3) + 1;\r
     ShellPrintEx ((INT32)Pos - 1, (INT32)Row - 1, L"   ");\r
@@ -379,7 +379,7 @@ HBufferImagePrintLine (
   //\r
   // restore the original color\r
   //\r
-  gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
+  gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);\r
 \r
   //\r
   // PRINT the buffer content\r
@@ -580,8 +580,9 @@ HBufferImageRestoreMousePosition (
       // backup the old screen attributes\r
       //\r
       Orig                  = HMainEditor.ColorAttributes;\r
-      New.Colors.Foreground = Orig.Colors.Background;\r
-      New.Colors.Background = Orig.Colors.Foreground;\r
+      New.Data              = 0;\r
+      New.Colors.Foreground = Orig.Colors.Background & 0xF;\r
+      New.Colors.Background = Orig.Colors.Foreground & 0x7;\r
 \r
       //\r
       // if in selected area,\r
@@ -593,7 +594,7 @@ HBufferImageRestoreMousePosition (
             )) {\r
         gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
       } else {\r
-        gST->ConOut->SetAttribute (gST->ConOut, New.Data);\r
+        gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);\r
       }\r
       //\r
       // clear the old mouse position\r
@@ -645,7 +646,7 @@ HBufferImageRestoreMousePosition (
             HBufferImage.MousePosition.Row,\r
             HBufferImage.MousePosition.Column\r
             )) {\r
-        gST->ConOut->SetAttribute (gST->ConOut, New.Data);\r
+        gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);\r
       } else {\r
         gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);\r
       }\r
@@ -731,7 +732,7 @@ HBufferImageRestorePosition (
   return EFI_SUCCESS;\r
 }\r
 \r
-/**
+/**\r
   Refresh function for HBufferImage.\r
 \r
   @retval EFI_SUCCESS     The operation was successful.\r
@@ -755,6 +756,7 @@ HBufferImageRefresh (
   UINTN                   Tmp;\r
 \r
   Orig                  = HMainEditor.ColorAttributes;\r
+  New.Data              = 0;\r
   New.Colors.Foreground = Orig.Colors.Background;\r
   New.Colors.Background = Orig.Colors.Foreground;\r
 \r
@@ -904,7 +906,6 @@ HBufferImageRefresh (
   @return EFI_SUCCESS     The operation was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 HBufferImageRead (\r
   IN CONST CHAR16                   *FileName,\r
   IN CONST CHAR16                   *DiskName,\r
@@ -1025,7 +1026,7 @@ HBufferImageSave (
   return Status;\r
 }\r
 \r
-/**
+/**\r
   Create a new line and append it to the line list.\r
     Fields affected:\r
     NumLines\r
@@ -1072,7 +1073,7 @@ HBufferImageCreateLine (
   return Line;\r
 }\r
 \r
-/**
+/**\r
   Free the current image.\r
 \r
   @retval EFI_SUCCESS   The operation was successful.\r
@@ -1090,7 +1091,7 @@ HBufferImageFree (
   return EFI_SUCCESS;\r
 }\r
 \r
-/**
+/**\r
   change char to int value based on Hex.\r
 \r
   @param[in] Char     The input char.\r
@@ -1099,7 +1100,6 @@ HBufferImageFree (
   @retval -1  The operation failed.\r
 **/\r
 INTN\r
-EFIAPI\r
 HBufferImageCharToHex (\r
   IN CHAR16 Char\r
   )\r
@@ -1108,15 +1108,15 @@ HBufferImageCharToHex (
   // change the character to hex\r
   //\r
   if (Char >= L'0' && Char <= L'9') {\r
-    return (INTN) (Char - L'0');\r
+    return (Char - L'0');\r
   }\r
 \r
   if (Char >= L'a' && Char <= L'f') {\r
-    return (INTN) (Char - L'a' + 10);\r
+    return (Char - L'a' + 10);\r
   }\r
 \r
   if (Char >= L'A' && Char <= L'F') {\r
-    return (INTN) (Char - L'A' + 10);\r
+    return (Char - L'A' + 10);\r
   }\r
 \r
   return -1;\r
@@ -1131,7 +1131,6 @@ HBufferImageCharToHex (
   @retval EFI_OUT_OF_RESOURCES    A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 HBufferImageAddChar (\r
   IN  CHAR16  Char\r
   )\r
@@ -1262,7 +1261,6 @@ HBufferImageAddChar (
   @retval EFI_SUCCESS   The operationw as successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 HBufferImageDoBackspace (\r
   VOID\r
   )\r
@@ -1326,7 +1324,6 @@ HBufferImageDoBackspace (
   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 HBufferImageDoCharInput (\r
   IN  CHAR16  Char\r
   )\r
@@ -2117,7 +2114,6 @@ HBufferImageAddCharacterToBuffer (
   @retval EFI_SUCCESS   The operationw as successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 HBufferImageDoDelete (\r
   VOID\r
   )\r
@@ -2178,7 +2174,6 @@ HBufferImageDoDelete (
   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 HBufferImageBufferToList (\r
   IN VOID   *Buffer,\r
   IN UINTN  Bytes\r
@@ -2243,7 +2238,6 @@ HBufferImageBufferToList (
   @retval EFI_SUCCESS   The operation was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 HBufferImageListToBuffer (\r
   IN VOID   *Buffer,\r
   IN UINTN  Bytes\r
@@ -2298,7 +2292,6 @@ HBufferImageListToBuffer (
   @param[in] TextY    The y-coordinate.\r
 **/\r
 VOID\r
-EFIAPI\r
 HBufferImageAdjustMousePosition (\r
   IN INT32 TextX,\r
   IN INT32 TextY\r