summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Universal/HiiDatabaseDxe
diff options
context:
space:
mode:
authorEric Dong <eric.dong@intel.com>2016-01-25 03:38:19 +0000
committerydong10 <ydong10@Edk2>2016-01-25 03:38:19 +0000
commit2a244a5d9f1b16517caf92114ec3e09bdb9c37a5 (patch)
tree3502430ad5cb5c73da4b896679ab1b030384513b /MdeModulePkg/Universal/HiiDatabaseDxe
parent95055567a626f5d55d46a42fc4c7198a80389467 (diff)
downloadedk2-2a244a5d9f1b16517caf92114ec3e09bdb9c37a5.tar.gz
edk2-2a244a5d9f1b16517caf92114ec3e09bdb9c37a5.tar.bz2
edk2-2a244a5d9f1b16517caf92114ec3e09bdb9c37a5.zip
MdeModulePkg: HiiDatabase: Refine the code to make it more safely.
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
Diffstat (limited to 'MdeModulePkg/Universal/HiiDatabaseDxe')
-rw-r--r--MdeModulePkg/Universal/HiiDatabaseDxe/Image.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
index 560cf8fe2c..c46c96545e 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
@@ -2,7 +2,7 @@
Implementation for EFI_HII_IMAGE_PROTOCOL.
-Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -266,7 +266,7 @@ Output1bitPixel (
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BitMapPtr;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue[2];
EFI_HII_IMAGE_PALETTE_INFO *Palette;
- UINT16 PaletteSize;
+ UINTN PaletteSize;
UINT8 Byte;
ASSERT (Image != NULL && Data != NULL && PaletteInfo != NULL);
@@ -276,10 +276,14 @@ Output1bitPixel (
//
// First entry corresponds to color 0 and second entry corresponds to color 1.
//
+ PaletteSize = 0;
CopyMem (&PaletteSize, PaletteInfo, sizeof (UINT16));
PaletteSize += sizeof (UINT16);
Palette = AllocateZeroPool (PaletteSize);
ASSERT (Palette != NULL);
+ if (Palette == NULL) {
+ return;
+ }
CopyMem (Palette, PaletteInfo, PaletteSize);
ZeroMem (PaletteValue, sizeof (PaletteValue));
@@ -350,7 +354,7 @@ Output4bitPixel (
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BitMapPtr;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue[16];
EFI_HII_IMAGE_PALETTE_INFO *Palette;
- UINT16 PaletteSize;
+ UINTN PaletteSize;
UINT16 PaletteNum;
UINT8 Byte;
@@ -361,10 +365,14 @@ Output4bitPixel (
//
// The bitmap should allocate each color index starting from 0.
//
+ PaletteSize = 0;
CopyMem (&PaletteSize, PaletteInfo, sizeof (UINT16));
PaletteSize += sizeof (UINT16);
Palette = AllocateZeroPool (PaletteSize);
ASSERT (Palette != NULL);
+ if (Palette == NULL) {
+ return;
+ }
CopyMem (Palette, PaletteInfo, PaletteSize);
PaletteNum = (UINT16)(Palette->PaletteSize / sizeof (EFI_HII_RGB_PIXEL));
@@ -424,7 +432,7 @@ Output8bitPixel (
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BitMapPtr;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL PaletteValue[256];
EFI_HII_IMAGE_PALETTE_INFO *Palette;
- UINT16 PaletteSize;
+ UINTN PaletteSize;
UINT16 PaletteNum;
UINT8 Byte;
@@ -435,10 +443,14 @@ Output8bitPixel (
//
// The bitmap should allocate each color index starting from 0.
//
+ PaletteSize = 0;
CopyMem (&PaletteSize, PaletteInfo, sizeof (UINT16));
PaletteSize += sizeof (UINT16);
Palette = AllocateZeroPool (PaletteSize);
ASSERT (Palette != NULL);
+ if (Palette == NULL) {
+ return;
+ }
CopyMem (Palette, PaletteInfo, PaletteSize);
PaletteNum = (UINT16)(Palette->PaletteSize / sizeof (EFI_HII_RGB_PIXEL));
ZeroMem (PaletteValue, sizeof (PaletteValue));