]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Refine code to make it more safely.
authorEric Dong <eric.dong@intel.com>
Thu, 26 Jun 2014 03:24:25 +0000 (03:24 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 26 Jun 2014 03:24:25 +0000 (03:24 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15598 6f19259b-4bc3-4df7-8a09-765794883524

21 files changed:
MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c
MdeModulePkg/Bus/Pci/UhciPei/UhcPeim.c
MdeModulePkg/Core/Dxe/FwVol/FwVolRead.c
MdeModulePkg/Core/Pei/Dependency/Dependency.c
MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
MdeModulePkg/Universal/HiiDatabaseDxe/Font.c
MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c
MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c
MdeModulePkg/Universal/Network/IScsiDxe/IScsiMisc.c
MdeModulePkg/Universal/Network/Ip4Dxe/Ip4If.c
MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c
MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Wrq.c
MdeModulePkg/Universal/Network/SnpDxe/Snp.c
MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcDhcp.c
MdeModulePkg/Universal/PlatformDriOverrideDxe/PlatDriOverrideDxe.c
MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c
MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c
MdeModulePkg/Universal/SetupBrowserDxe/Setup.c

index cc9b06aa9b0ce000c867f2f7917364ae42d53da9..d638ebaeb9b3a60370ebbb32edb446fc0fee0248 100644 (file)
@@ -3,7 +3,7 @@ PEIM to produce gEfiPeiVirtualBlockIoPpiGuid PPI for ATA controllers in the plat
 This PPI canl be consumed by PEIM which produce gEfiPeiDeviceRecoveryModulePpiGuid\r
 for Atapi CD ROM device.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
 \r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions\r
@@ -1442,6 +1442,7 @@ Inquiry (
   // prepare command packet for the ATAPI Inquiry Packet Command.\r
   //\r
   ZeroMem (&Packet, sizeof (ATAPI_PACKET_COMMAND));\r
+  ZeroMem (&Idata, sizeof (ATAPI_INQUIRY_DATA));\r
 \r
   Packet.Inquiry.opcode             = ATA_CMD_INQUIRY;\r
   Packet.Inquiry.page_code          = 0;\r
index 33f8c45d810724583d5d4911314cbdb414652f4b..368b75d75304b817b7981eb41115b144b4567d9f 100644 (file)
@@ -2,7 +2,7 @@
 PEIM to produce gPeiUsbHostControllerPpiGuid based on gPeiUsbControllerPpiGuid\r
 which is used to enable recovery function from USB Drivers.\r
 \r
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved. <BR>\r
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved. <BR>\r
   \r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions\r
@@ -1047,11 +1047,13 @@ CreateFrameList (
   if (Status != EFI_SUCCESS) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  \r
+  ASSERT (UhcDev->ConfigQH != NULL);\r
+\r
   Status = CreateQH(UhcDev, &UhcDev->BulkQH);\r
   if (Status != EFI_SUCCESS) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
+  ASSERT (UhcDev->BulkQH != NULL);\r
 \r
   //\r
   //Set the corresponding QH pointer \r
index b5a0d874f05fb652fc011101c4cc906c99c2b1e4..f2c0dd5de42e0593211750d299de93d39f17d680 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implements functions to read firmware file\r
 \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, 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
@@ -447,6 +447,7 @@ FvReadFileSection (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
+  ASSERT (FileBuffer != NULL);\r
 \r
   //\r
   // Check to see that the file actually HAS sections before we go any further.\r
index d209b8d505386a05bbd6a751c3b8d2d9c2fc559f..e71566b5a74ec12cc229c6ec2b5bde9c57b25697 100644 (file)
@@ -5,7 +5,7 @@
   if a driver can be scheduled for execution.  The criteria for\r
   schedulability is that the dependency expression is satisfied.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, 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
@@ -106,7 +106,7 @@ PeimDispatchReadiness (
 \r
   Iterator  = DependencyExpression;\r
 \r
-  StackPtr = &EvalStack[0];\r
+  StackPtr = EvalStack;\r
 \r
   while (TRUE) {\r
 \r
index 10eef05098e0c04779a18c8ad821db6d9502600a..84c6c9af1f13208eb419f09df70fbb1aeae3dbfc 100644 (file)
@@ -388,7 +388,7 @@ SetPassword (
   //\r
   // Get user input password\r
   //\r
-  Password = &PrivateData->Configuration.WhatIsThePassword2[0];\r
+  Password = PrivateData->Configuration.WhatIsThePassword2;\r
   PasswordSize = sizeof (PrivateData->Configuration.WhatIsThePassword2);\r
   ZeroMem (Password, PasswordSize);\r
 \r
index 0011c53e6f512e7fe40ef20982def785c2d3d495..f5e054d26577ab9bfa1dab1895fab96d26a242ba 100644 (file)
@@ -4339,6 +4339,7 @@ HiiConfigRoutingRouteConfig (
                                );\r
     }\r
     if (EFI_ERROR (Status)) {\r
+      ASSERT (AccessProgress != NULL);\r
       //\r
       // AccessProgress indicates the parsing progress on <ConfigResp>.\r
       // Map it to the progress on <MultiConfigResp> then return it.\r
index 65334ded5ed30fafbfd30241edc71a47dd8e18eb..01d7f02234ad30700f8fc6412e7699285f6e3da9 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Implementation for EFI_HII_DATABASE_PROTOCOL.\r
 \r
-Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2014, 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
@@ -2419,6 +2419,7 @@ AddPackages (
   //\r
   StringPkgIsAdd = FALSE;\r
   FontPackage = NULL;\r
+  StringPackage = NULL;\r
 \r
   //\r
   // Process the package list header\r
@@ -2505,6 +2506,7 @@ AddPackages (
       if (EFI_ERROR (Status)) {\r
         return Status;\r
       }\r
+      ASSERT (StringPackage != NULL);\r
       Status = InvokeRegisteredFunction (\r
                  Private,\r
                  NotifyType,\r
index 24bb502996a83b9bd3301b582521fa48d326d00f..eef31d5bb833b94529234a0d81d8ddd8ea59522a 100644 (file)
@@ -2,7 +2,7 @@
 Implementation for EFI_HII_FONT_PROTOCOL.\r
 \r
 \r
-Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2014, 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
@@ -1040,8 +1040,12 @@ IsSystemFontInfo (
     return TRUE;\r
   }\r
 \r
+  SystemDefault = NULL;\r
+  DefaultLen    = 0;\r
+\r
   Status = GetSystemFont (Private, &SystemDefault, &DefaultLen);\r
   ASSERT_EFI_ERROR (Status);\r
+  ASSERT ((SystemDefault != NULL) && (DefaultLen != 0));\r
 \r
   //\r
   // Record the system default info.\r
@@ -1687,6 +1691,7 @@ HiiStringToImage (
   SysFontFlag   = IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfo, &SystemDefault, NULL);\r
 \r
   if (SysFontFlag) {\r
+    ASSERT (SystemDefault != NULL);\r
     FontInfo   = NULL;\r
     Height     = SystemDefault->FontInfo.FontSize;\r
     BaseLine   = SystemDefault->FontInfo.FontSize;\r
@@ -2580,6 +2585,7 @@ HiiGetGlyph (
     Foreground = StringInfoOut->ForegroundColor;\r
     Background = StringInfoOut->BackgroundColor;\r
   } else {\r
+    ASSERT (SystemDefault != NULL);\r
     Foreground = SystemDefault->ForegroundColor;\r
     Background = SystemDefault->BackgroundColor;\r
   }\r
@@ -2723,6 +2729,7 @@ HiiGetFontInfo (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  StringInfoOutLen = 0;\r
   FontInfo        = NULL;\r
   SystemDefault   = NULL;\r
   LocalFontHandle = NULL;\r
index efa5bbb71b8b5e3002bd3bc819abfeca2198fbf6..ed0cf83c483df72df9eb348dedb5880111f858cf 100644 (file)
@@ -2,7 +2,7 @@
 Implementation for EFI_HII_IMAGE_PROTOCOL.\r
 \r
 \r
-Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2014, 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
@@ -1237,6 +1237,7 @@ HiiDrawImage (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  FontInfo = NULL;\r
   ImageIn = (EFI_IMAGE_INPUT *) Image;\r
 \r
   //\r
@@ -1383,6 +1384,7 @@ HiiDrawImage (
       FreePool (ImageOut);\r
       return Status;\r
     }\r
+    ASSERT (FontInfo != NULL);\r
     for (Index = 0; Index < Width * Height; Index++) {\r
       BltBuffer[Index] = FontInfo->BackgroundColor;\r
     }\r
index 19ad101d5404d812998568727fdbb7175f43e72c..995bbcf840bfdd5201e7b798c543c57117853567 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   EFI DHCP protocol implementation.\r
   \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, 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
@@ -404,6 +404,7 @@ DhcpLeaseAcquired (
 \r
   if (DhcpSb->Netmask == 0) {\r
     Class           = NetGetIpClass (DhcpSb->ClientAddr);\r
+    ASSERT (Class < IP4_ADDR_CLASSE);\r
     DhcpSb->Netmask = gIp4AllMasks[Class << 3];\r
   }\r
 \r
index a9c6df9db9611c288cbb3ab8baa9b2e1ec9bc1e0..f8ae161b4c68215030527b2cae39384b76130610 100644 (file)
@@ -227,6 +227,7 @@ IScsiUpdateDeviceList (
                   );\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
     DeviceList = (ISCSI_DEVICE_LIST *) AllocatePool (DataSize);\r
+    ASSERT (DeviceList != NULL);\r
 \r
     gRT->GetVariable (\r
           L"iSCSIDeviceList",\r
@@ -291,6 +292,7 @@ IScsiUpdateDeviceList (
   //\r
   DeviceListSize        = sizeof (ISCSI_DEVICE_LIST) + (NumHandles - 1) * sizeof (ISCSI_MAC_INFO);\r
   DeviceList            = (ISCSI_DEVICE_LIST *) AllocatePool (DeviceListSize);\r
+  ASSERT (DeviceList != NULL);\r
   DeviceList->NumDevice = (UINT8) NumHandles;\r
 \r
   for (Index = 0; Index < NumHandles; Index++) {\r
index a00d805b84c4758363103dc4acc68750d9583a5b..1cb1fb89d9ec97c44160a8f6f28ddb3f189537be 100644 (file)
@@ -219,6 +219,7 @@ IScsiLunToUnicodeStr (
     TempStr += StrLen (TempStr);\r
   }\r
 \r
+  ASSERT (StrLen(Str) >= 1);\r
   Str[StrLen (Str) - 1] = 0;\r
 \r
   for (Index = StrLen (Str) - 1; Index > 1; Index = Index - 2) {\r
index e4ab17a37ea555a9c10206f8e474d0c47fc41bed..3c29f75f886d29891fa6d32ea60847bb54214396 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implement IP4 pesudo interface.\r
   \r
-Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2014, 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
@@ -582,6 +582,7 @@ Ip4SetAddress (
 \r
   Type                      = NetGetIpClass (IpAddr);\r
   Len                       = NetGetMaskLength (SubnetMask);\r
+  ASSERT (Len >= 1);\r
   Netmask                   = gIp4AllMasks[MIN ((Len - 1), Type << 3)];\r
   Interface->NetBrdcast     = (IpAddr | ~Netmask);\r
 \r
index ae157c5e0a6ed7ec059a763b0010ffe797abb1f8..21547ee3af8dadbc4a848a0ab37f7df4b48ab939 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Routines to process Rrq (download).\r
   \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, 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
@@ -704,6 +704,7 @@ Mtftp4RrqInput (
 \r
   } else {\r
     Packet = (EFI_MTFTP4_PACKET *) NetbufGetByte (UdpPacket, 0, NULL);\r
+    ASSERT (Packet != NULL);\r
   }\r
 \r
   Opcode = NTOHS (Packet->OpCode);\r
index 412c472e42e6c93878477d8a32c623ce8a5eb9da..e8257147006bff793a58e9f3d772e26c07bb5f6f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Routines to process Wrq (upload).\r
   \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, 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
@@ -398,6 +398,7 @@ Mtftp4WrqInput (
 \r
   } else {\r
     Packet = (EFI_MTFTP4_PACKET *) NetbufGetByte (UdpPacket, 0, NULL);\r
+    ASSERT (Packet != NULL);\r
   }\r
 \r
   Opcode = NTOHS (Packet->OpCode);\r
index ed583b488832d0326e1c6e60a7d81c4bc5ec82d0..ff93167767c7a8293fbe4fa4f5ddf8f4a78533f8 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implementation of driver entry point and driver binding protocol.\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed\r
 and made available under the terms and conditions of the BSD License which\r
 accompanies this distribution. The full text of the license may be found at\r
@@ -545,8 +545,8 @@ SimpleNetworkDriverStart (
   // the IO BAR.  Save the index of the BAR into the adapter info structure.\r
   // for  regular 32bit BARs, 0 is memory mapped, 1 is io mapped\r
   //\r
-  ConfigHeader  = (PCI_TYPE00 *) &ConfigInfo.Config.Byte[0];\r
-  TempBar       = (UINT32 *) &ConfigHeader->Device.Bar[0];\r
+  ConfigHeader  = (PCI_TYPE00 *) ConfigInfo.Config.Byte;\r
+  TempBar       = (UINT32 *) ConfigHeader->Device.Bar;\r
   for (BarIndex = 0; BarIndex <= 5; BarIndex++) {\r
     if ((*TempBar & PCI_BAR_MEM_MASK) == PCI_BAR_MEM_64BIT) {\r
       //\r
index e016cc0f5118fde59830da90ca926b19a9ffb169..1293f672686bd474c2a945d41711f5259a657035 100644 (file)
@@ -477,6 +477,7 @@ PxeBcCheckSelectedOffer (
         //\r
         Status = EFI_NO_RESPONSE;\r
 \r
+        ASSERT (Private->NumOffers < PXEBC_MAX_OFFER_NUM);\r
         for (Index = 0; Index < Private->NumOffers; Index++) {\r
 \r
           Offer = &Private->Dhcp4Offers[Index].Packet.Offer;\r
index 3c55a785fca4827c16e5b8abe9adb955fb5b4501..0f0da166ad9984dda31826cbf54112dfe02afbc3 100644 (file)
@@ -123,10 +123,11 @@ DevicePathToStr (
            TRUE\r
            );\r
   if (Text == NULL) {\r
-    return AllocateCopyPool (sizeof (L"?"), L"?");\r
-  } else {\r
-    return Text;\r
+    Text = AllocateCopyPool (sizeof (L"?"), L"?");\r
+    ASSERT (Text != NULL);\r
   }\r
+\r
+  return Text;\r
 }\r
 \r
 /**\r
index e806b504b2934fdc4079d02b928dd862f48db7ca..22f257dd4eceeda32a9dabf0f837e89ebf3337c6 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Parser for IFR binary encoding.\r
 \r
-Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2014, 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
@@ -663,6 +663,7 @@ InitializeRequestElement (
     ASSERT (ConfigInfo != NULL);\r
     ConfigInfo->Signature     = FORM_BROWSER_CONFIG_REQUEST_SIGNATURE;\r
     ConfigInfo->ConfigRequest = AllocateCopyPool (StrSize (Storage->ConfigHdr), Storage->ConfigHdr);\r
+    ASSERT (ConfigInfo->ConfigRequest != NULL);\r
     ConfigInfo->SpareStrLen   = 0;\r
     ConfigInfo->Storage       = Storage;\r
     InsertTailList(&Form->ConfigRequestHead, &ConfigInfo->Link);\r
@@ -2327,6 +2328,7 @@ ParseOpCodes (
         break;\r
 \r
       case EFI_IFR_ONE_OF_OPTION_OP:\r
+        ASSERT (CurrentOption != NULL);\r
         ImageId = &CurrentOption->ImageId;\r
         break;\r
 \r
index bad8b7b122ea72d567fc27a599c659ef607bb2f9..f06b8a20d4f1e1485f70a638e133bc49cbbefb2b 100644 (file)
@@ -397,8 +397,11 @@ UpdateHotkeyList (
     HotKey = BROWSER_HOT_KEY_FROM_LINK (Link);\r
 \r
     CopyKey             = AllocateCopyPool(sizeof (BROWSER_HOT_KEY), HotKey);\r
+    ASSERT (CopyKey != NULL);\r
     CopyKey->KeyData    = AllocateCopyPool(sizeof (EFI_INPUT_KEY), HotKey->KeyData);\r
+    ASSERT (CopyKey->KeyData != NULL);\r
     CopyKey->HelpString = AllocateCopyPool(StrSize (HotKey->HelpString), HotKey->HelpString);\r
+    ASSERT (CopyKey->HelpString != NULL);\r
 \r
     InsertTailList(&gDisplayFormData.HotKeyListHead, &CopyKey->Link);\r
 \r
@@ -1977,6 +1980,7 @@ ProcessCallBackFunction (
     if (Action == EFI_BROWSER_ACTION_CHANGING) {\r
       if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) {\r
         BackUpBuffer = AllocateCopyPool(Statement->StorageWidth + sizeof(CHAR16), Statement->BufferValue);\r
+        ASSERT (BackUpBuffer != NULL);\r
       } else {\r
         CopyMem (&BackUpValue, &HiiValue->Value, sizeof (EFI_IFR_TYPE_VALUE));\r
       }\r
index 3f2f1b5468dad799f434d89707aec4a4e00e7e56..4ba0cb0903329d58fad80d852716855fa14b803e 100644 (file)
@@ -4060,8 +4060,11 @@ GetDefaultForFormset (
       }\r
 \r
       TmpNode = AllocateCopyPool (sizeof (NAME_VALUE_NODE), Node);\r
+      ASSERT (TmpNode != NULL);\r
       TmpNode->Name = AllocateCopyPool (StrSize(Node->Name) * sizeof (CHAR16), Node->Name);\r
+      ASSERT (TmpNode->Name != NULL);\r
       TmpNode->EditValue = AllocateCopyPool (StrSize(Node->EditValue) * sizeof (CHAR16), Node->EditValue);\r
+      ASSERT (TmpNode->EditValue != NULL);\r
 \r
       InsertTailList(&BackUpList, &TmpNode->Link);\r
     }\r