]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: HiiDatabase: Refine the code to make it more safely.
authorEric Dong <eric.dong@intel.com>
Mon, 25 Jan 2016 03:38:19 +0000 (03:38 +0000)
committerydong10 <ydong10@Edk2>
Mon, 25 Jan 2016 03:38:19 +0000 (03:38 +0000)
Refine the code to avoid potential buffer overflow or use NULL pointer.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19735 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/HiiDatabaseDxe/Image.c

index 560cf8fe2cffbc60166ea201b4d693cfce3a2c64..c46c96545e80ab8ae93b9fa0525f226ba1d040a5 100644 (file)
@@ -2,7 +2,7 @@
 Implementation for EFI_HII_IMAGE_PROTOCOL.\r
 \r
 \r
-Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2016, 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
@@ -266,7 +266,7 @@ Output1bitPixel (
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL      *BitMapPtr;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL      PaletteValue[2];\r
   EFI_HII_IMAGE_PALETTE_INFO         *Palette;\r
-  UINT16                             PaletteSize;\r
+  UINT                             PaletteSize;\r
   UINT8                              Byte;\r
 \r
   ASSERT (Image != NULL && Data != NULL && PaletteInfo != NULL);\r
@@ -276,10 +276,14 @@ Output1bitPixel (
   //\r
   // First entry corresponds to color 0 and second entry corresponds to color 1.\r
   //\r
+  PaletteSize = 0;\r
   CopyMem (&PaletteSize, PaletteInfo, sizeof (UINT16));\r
   PaletteSize += sizeof (UINT16);\r
   Palette = AllocateZeroPool (PaletteSize);\r
   ASSERT (Palette != NULL);\r
+  if (Palette == NULL) {\r
+    return;\r
+  }\r
   CopyMem (Palette, PaletteInfo, PaletteSize);\r
 \r
   ZeroMem (PaletteValue, sizeof (PaletteValue));\r
@@ -350,7 +354,7 @@ Output4bitPixel (
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL      *BitMapPtr;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL      PaletteValue[16];\r
   EFI_HII_IMAGE_PALETTE_INFO         *Palette;\r
-  UINT16                             PaletteSize;\r
+  UINT                             PaletteSize;\r
   UINT16                             PaletteNum;\r
   UINT8                              Byte;\r
 \r
@@ -361,10 +365,14 @@ Output4bitPixel (
   //\r
   // The bitmap should allocate each color index starting from 0.\r
   //\r
+  PaletteSize = 0;\r
   CopyMem (&PaletteSize, PaletteInfo, sizeof (UINT16));\r
   PaletteSize += sizeof (UINT16);\r
   Palette = AllocateZeroPool (PaletteSize);\r
   ASSERT (Palette != NULL);\r
+  if (Palette == NULL) {\r
+    return;\r
+  }\r
   CopyMem (Palette, PaletteInfo, PaletteSize);\r
   PaletteNum = (UINT16)(Palette->PaletteSize / sizeof (EFI_HII_RGB_PIXEL));\r
 \r
@@ -424,7 +432,7 @@ Output8bitPixel (
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL      *BitMapPtr;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL      PaletteValue[256];\r
   EFI_HII_IMAGE_PALETTE_INFO         *Palette;\r
-  UINT16                             PaletteSize;\r
+  UINT                             PaletteSize;\r
   UINT16                             PaletteNum;\r
   UINT8                              Byte;\r
 \r
@@ -435,10 +443,14 @@ Output8bitPixel (
   //\r
   // The bitmap should allocate each color index starting from 0.\r
   //\r
+  PaletteSize = 0;\r
   CopyMem (&PaletteSize, PaletteInfo, sizeof (UINT16));\r
   PaletteSize += sizeof (UINT16);\r
   Palette = AllocateZeroPool (PaletteSize);\r
   ASSERT (Palette != NULL);\r
+  if (Palette == NULL) {\r
+    return;\r
+  }\r
   CopyMem (Palette, PaletteInfo, PaletteSize);\r
   PaletteNum = (UINT16)(Palette->PaletteSize / sizeof (EFI_HII_RGB_PIXEL));\r
   ZeroMem (PaletteValue, sizeof (PaletteValue));\r