]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/GraphicsLib/Graphics.c
Merger trackers #7807 and #8372.
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GraphicsLib / Graphics.c
index 6e1c3f82a81eddeb44e460bc56577dee136a4d7e..50eb1f56bc0d58f18ddbb84f6b6eb39bf97666c0 100644 (file)
@@ -34,7 +34,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/BaseLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
-\r
+#include <Library/DebugLib.h>\r
 \r
 EFI_STATUS\r
 GetGraphicsBitMapFromFV (\r
@@ -133,8 +133,8 @@ ConvertBmpToGopBlt (
 \r
 Routine Description:\r
 \r
-  Convert a *.BMP graphics image to a UGA blt buffer. If a NULL UgaBlt buffer\r
-  is passed in a UgaBlt buffer will be allocated by this routine. If a UgaBlt\r
+  Convert a *.BMP graphics image to a GOP/UGA blt buffer. If a NULL Blt buffer\r
+  is passed in a GopBlt buffer will be allocated by this routine. If a GopBlt\r
   buffer is passed in it will be used if it is big enough.\r
 \r
 Arguments:\r
@@ -143,21 +143,21 @@ Arguments:
 \r
   BmpImageSize  - Number of bytes in BmpImage\r
 \r
-  UgaBlt        - Buffer containing UGA version of BmpImage.\r
+  GopBlt        - Buffer containing GOP version of BmpImage.\r
 \r
-  UgaBltSize    - Size of UgaBlt in bytes.\r
+  GopBltSize    - Size of GopBlt in bytes.\r
 \r
-  PixelHeight   - Height of UgaBlt/BmpImage in pixels\r
+  PixelHeight   - Height of GopBlt/BmpImage in pixels\r
 \r
-  PixelWidth    - Width of UgaBlt/BmpImage in pixels\r
+  PixelWidth    - Width of GopBlt/BmpImage in pixels\r
 \r
 \r
 Returns:\r
 \r
-  EFI_SUCCESS           - UgaBlt and UgaBltSize are returned.\r
+  EFI_SUCCESS           - GopBlt and GopBltSize are returned.\r
   EFI_UNSUPPORTED       - BmpImage is not a valid *.BMP image\r
-  EFI_BUFFER_TOO_SMALL  - The passed in UgaBlt buffer is not big enough.\r
-                          UgaBltSize will contain the required size.\r
+  EFI_BUFFER_TOO_SMALL  - The passed in GopBlt buffer is not big enough.\r
+                          GopBltSize will contain the required size.\r
   EFI_OUT_OF_RESOURCES  - No enough buffer to allocate\r
 \r
 --*/\r
@@ -575,8 +575,8 @@ DisableQuietBoot (
 \r
 Routine Description:\r
 \r
-  Use Console Control to turn on UGA based Simple Text Out consoles. The UGA\r
-  Simple Text Out screens will now be synced up with all non UGA output devices\r
+  Use Console Control to turn on GOP/UGA based Simple Text Out consoles. The GOP/UGA\r
+  Simple Text Out screens will now be synced up with all non GOP/UGA output devices\r
 \r
 Arguments:\r
 \r
@@ -584,7 +584,7 @@ Arguments:
 \r
 Returns:\r
 \r
-  EFI_SUCCESS           - UGA devices are back in text mode and synced up.\r
+  EFI_SUCCESS           - GOP/UGA devices are back in text mode and synced up.\r
   EFI_UNSUPPORTED       - Logo not found\r
 \r
 --*/\r
@@ -665,21 +665,23 @@ Returns:
 \r
 --*/\r
 {\r
-  VOID              *Buffer;\r
-  EFI_STATUS        Status;\r
-  UINT16            GlyphWidth;\r
-  UINT32            GlyphStatus;\r
-  UINT16            StringIndex;\r
-  UINTN             Index;\r
-  CHAR16            *UnicodeWeight;\r
-  EFI_NARROW_GLYPH  *Glyph;\r
-  EFI_HII_PROTOCOL  *Hii;\r
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL     *LineBuffer;\r
-  UINT32            HorizontalResolution;\r
-  UINT32            VerticalResolution;\r
-  UINT32            ColorDepth;\r
-  UINT32            RefreshRate;\r
-  UINTN             BufferGlyphWidth;\r
+  VOID                           *Buffer;\r
+  EFI_STATUS                     Status;\r
+  UINT16                         GlyphWidth;\r
+  UINT32                         GlyphStatus;\r
+  UINT16                         StringIndex;\r
+  UINTN                          Index;\r
+  CHAR16                         *UnicodeWeight;\r
+  EFI_NARROW_GLYPH               *Glyph;\r
+  EFI_HII_PROTOCOL               *Hii;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL  *LineBuffer;\r
+  UINT32                         HorizontalResolution;\r
+  UINT32                         VerticalResolution;\r
+  UINT32                         ColorDepth;\r
+  UINT32                         RefreshRate;\r
+  UINTN                          BufferLen;\r
+  UINTN                          LineBufferLen;\r
+  UINTN                          BufferGlyphWidth;\r
 \r
   GlyphStatus = 0;\r
 \r
@@ -700,8 +702,10 @@ Returns:
     //\r
     UgaDraw->GetMode (UgaDraw, &HorizontalResolution, &VerticalResolution, &ColorDepth, &RefreshRate);\r
   }\r
+  ASSERT ((HorizontalResolution != 0) && (VerticalResolution !=0));\r
 \r
-  LineBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * HorizontalResolution * GLYPH_WIDTH * GLYPH_HEIGHT);\r
+  LineBufferLen = sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * HorizontalResolution * GLYPH_HEIGHT;\r
+  LineBuffer = AllocatePool (LineBufferLen);\r
   if (LineBuffer == NULL) {\r
     gBS->FreePool (Buffer);\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -724,7 +728,14 @@ Returns:
     }\r
   }\r
 \r
-  for (Index = 0; Index < StrLen (Buffer); Index++) {\r
+  BufferLen = StrLen (Buffer);\r
+\r
+  if (GLYPH_WIDTH * GLYPH_HEIGHT * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) * BufferLen > LineBufferLen) {\r
+     Status = EFI_INVALID_PARAMETER;\r
+     goto Error;\r
+  }\r
+\r
+  for (Index = 0; Index < BufferLen; Index++) {\r
     StringIndex = (UINT16) Index;\r
     Status      = Hii->GetGlyph (Hii, UnicodeWeight, &StringIndex, (UINT8 **) &Glyph, &GlyphWidth, &GlyphStatus);\r
     if (EFI_ERROR (Status)) {\r
@@ -737,7 +748,7 @@ Returns:
                       (UINT8 *) Glyph,\r
                       mEfiColors[Sto->Mode->Attribute & 0x0f],\r
                       mEfiColors[Sto->Mode->Attribute >> 4],\r
-                      StrLen (Buffer),\r
+                      BufferLen,\r
                       GlyphWidth,\r
                       GLYPH_HEIGHT,\r
                       &LineBuffer[Index * GLYPH_WIDTH]\r
@@ -748,7 +759,7 @@ Returns:
                       (UINT8 *) Glyph,\r
                       *Foreground,\r
                       *Background,\r
-                      StrLen (Buffer),\r
+                      BufferLen,\r
                       GlyphWidth,\r
                       GLYPH_HEIGHT,\r
                       &LineBuffer[Index * GLYPH_WIDTH]\r
@@ -759,7 +770,7 @@ Returns:
   //\r
   // Blt a character to the screen\r
   //\r
-  BufferGlyphWidth = GLYPH_WIDTH * StrLen (Buffer);\r
+  BufferGlyphWidth = GLYPH_WIDTH * BufferLen;\r
   if (GraphicsOutput != NULL) {\r
     Status = GraphicsOutput->Blt (\r
                         GraphicsOutput,\r