IntelFsp2WrapperPkg: Add error handling for possible NULL ptr dereference
authorHao Wu <hao.a.wu@intel.com>
Thu, 30 Jun 2016 01:13:24 +0000 (09:13 +0800)
committerHao Wu <hao.a.wu@intel.com>
Fri, 1 Jul 2016 00:50:39 +0000 (08:50 +0800)
Possible NULL pointer dereference for FspmHeaderPtr/FspsHeaderPtr in
module FspmWrapperPeim/FspsWrapperPeim.

Add error handling codes to avoid this issue.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Giri P Mudusuru <giri.p.mudusuru@intel.com>
IntelFsp2WrapperPkg/FspmWrapperPeim/FspmWrapperPeim.c
IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.c

index 6144ad7..c98513e 100644 (file)
@@ -68,6 +68,11 @@ PeiFspMemoryInit (
   // Copy default FSP-M UPD data from Flash\r
   //\r
   FspmHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspmBaseAddress));\r
+  DEBUG ((DEBUG_INFO, "FspmHeaderPtr - 0x%x\n", FspmHeaderPtr));\r
+  if (FspmHeaderPtr == NULL) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
   FspmUpdDataPtr = (FSPM_UPD_COMMON *)AllocateZeroPool ((UINTN)FspmHeaderPtr->CfgRegionSize);\r
   ASSERT (FspmUpdDataPtr != NULL);\r
   SourceData = (UINTN *)((UINTN)FspmHeaderPtr->ImageBase + (UINTN)FspmHeaderPtr->CfgRegionOffset);\r
index 7a65ad7..c923690 100644 (file)
@@ -241,6 +241,11 @@ PeiMemoryDiscoveredNotify (
   // Copy default FSP-S UPD data from Flash\r
   //\r
   FspsHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspsBaseAddress));\r
+  DEBUG ((DEBUG_INFO, "FspsHeaderPtr - 0x%x\n", FspsHeaderPtr));\r
+  if (FspsHeaderPtr == NULL) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
   FspsUpdDataPtr = (FSPS_UPD_COMMON *)AllocateZeroPool ((UINTN)FspsHeaderPtr->CfgRegionSize);\r
   ASSERT (FspsUpdDataPtr != NULL);\r
   SourceData = (UINTN *)((UINTN)FspsHeaderPtr->ImageBase + (UINTN)FspsHeaderPtr->CfgRegionOffset);\r