]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Refine some code to make code run safely.
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 20 Sep 2010 03:20:56 +0000 (03:20 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 20 Sep 2010 03:20:56 +0000 (03:20 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10893 6f19259b-4bc3-4df7-8a09-765794883524

OptionRomPkg/AtapiPassThruDxe/AtapiPassThru.c
OptionRomPkg/CirrusLogic5430Dxe/CirrusLogic5430GraphicsOutput.c
OptionRomPkg/UndiRuntimeDxe/Decode.c
OptionRomPkg/UndiRuntimeDxe/E100b.c
OptionRomPkg/UndiRuntimeDxe/Init.c

index d2a9d7b11e51245cdc2ee4e914a275074e2d1013..3578a1e4459c97cd13bf167e53c39cb78714c783 100644 (file)
@@ -1749,10 +1749,12 @@ Returns:
 {\r
   UINT8 Index;\r
   UINT8 *OpCode;\r
+  UINT8 ArrayLen;\r
 \r
   OpCode = (UINT8 *) (Packet->Cdb);\r
+  ArrayLen = (UINT8) (sizeof (gSupportedATAPICommands) / sizeof (gSupportedATAPICommands[0]));\r
 \r
-  for (Index = 0; CompareMem (&gSupportedATAPICommands[Index], &gEndTable, sizeof (SCSI_COMMAND_SET)); Index++) {\r
+  for (Index = 0; (Index < ArrayLen) && (CompareMem (&gSupportedATAPICommands[Index], &gEndTable, sizeof (SCSI_COMMAND_SET)) != 0); Index++) {\r
 \r
     if (*OpCode == gSupportedATAPICommands[Index].OpCode) {\r
       //\r
@@ -1990,10 +1992,12 @@ Returns:
 {\r
   UINT8 Index;\r
   UINT8 *OpCode;\r
+  UINT8 ArrayLen;\r
 \r
   OpCode = (UINT8 *) (Packet->Cdb);\r
+  ArrayLen = (UINT8) (sizeof (gSupportedATAPICommands) / sizeof (gSupportedATAPICommands[0]));\r
 \r
-  for (Index = 0; CompareMem (&gSupportedATAPICommands[Index], &gEndTable, sizeof (SCSI_COMMAND_SET)); Index++) {\r
+  for (Index = 0; (Index < ArrayLen) && (CompareMem (&gSupportedATAPICommands[Index], &gEndTable, sizeof (SCSI_COMMAND_SET)) != 0); Index++) {\r
 \r
     if (*OpCode == gSupportedATAPICommands[Index].OpCode) {\r
       //\r
index 8ba2f98cb974a926e2b31c756ecbf13d5e0bd49d..d4b3eafb273828ef4114d840f8f4cc21037089a9 100644 (file)
@@ -523,6 +523,7 @@ CirrusLogic5430GraphicsOutputConstructor (
   // Initialize the hardware\r
   //\r
   GraphicsOutput->SetMode (GraphicsOutput, 0);\r
+  ASSERT (Private->GraphicsOutput.Mode->Mode < CIRRUS_LOGIC_5430_MODE_COUNT);\r
   DrawLogo (\r
     Private,\r
     Private->ModeData[Private->GraphicsOutput.Mode->Mode].HorizontalResolution,\r
index 56a70127872eed1a44f85ba7f5e6783cab0ea97d..0eabc2ad8fcd3f2df765dca8c10236c7a6ff5676 100644 (file)
@@ -254,9 +254,9 @@ UNDI_GetInitInfo (
   DbPtr->MCastFilterCnt = MAX_MCAST_ADDRESS_CNT;\r
 \r
   DbPtr->TxBufCnt = TX_BUFFER_COUNT;\r
-  DbPtr->TxBufSize = sizeof (TxCB);\r
+  DbPtr->TxBufSize = (UINT16) sizeof (TxCB);\r
   DbPtr->RxBufCnt = RX_BUFFER_COUNT;\r
-  DbPtr->RxBufSize = sizeof (RxFD);\r
+  DbPtr->RxBufSize = (UINT16) sizeof (RxFD);\r
 \r
   DbPtr->IFtype = PXE_IFTYPE_ETHERNET;\r
   DbPtr->SupportedDuplexModes = PXE_DUPLEX_ENABLE_FULL_SUPPORTED |\r
@@ -1032,7 +1032,7 @@ UNDI_Status (
     //\r
     // We already filled in 2 UINT32s.\r
     //\r
-    CdbPtr->DBsize = sizeof (UINT32) * 2;\r
+    CdbPtr->DBsize = (UINT16) (sizeof (UINT32) * 2);\r
 \r
     //\r
     // will claim any hanging free CBs\r
@@ -1042,7 +1042,7 @@ UNDI_Status (
     if (AdapterInfo->xmit_done_head == AdapterInfo->xmit_done_tail) {\r
       CdbPtr->StatFlags |= PXE_STATFLAGS_GET_STATUS_TXBUF_QUEUE_EMPTY;\r
     } else {\r
-      for (Index = 0; NumEntries >= sizeof (UINT64); Index++, NumEntries -= sizeof (UINT64)) {\r
+      for (Index = 0; ((Index < MAX_XMIT_BUFFERS) && (NumEntries >= sizeof (UINT64))); Index++, NumEntries -= sizeof (UINT64)) {\r
         if (AdapterInfo->xmit_done_head != AdapterInfo->xmit_done_tail) {\r
           DbPtr->TxBuffer[Index]      = AdapterInfo->xmit_done[AdapterInfo->xmit_done_head];\r
           AdapterInfo->xmit_done_head = next (AdapterInfo->xmit_done_head);\r
@@ -1476,7 +1476,7 @@ PxeStructInit (
   // Initialize the !PXE structure\r
   //\r
   PxePtr->Signature = PXE_ROMID_SIGNATURE;\r
-  PxePtr->Len       = sizeof (PXE_SW_UNDI);\r
+  PxePtr->Len       = (UINT8) sizeof (PXE_SW_UNDI);\r
   //\r
   // cksum\r
   //\r
index 6f953c319532cb40cad4d201ce696c669630c4d3..41308ba6fdafa361d799c5cdc892d164561d18de 100644 (file)
@@ -517,7 +517,8 @@ Configure (
   UINT8 my_filter;\r
 \r
   cmd_ptr   = GetFreeCB (AdapterInfo);\r
-  data_ptr  = (UINT8 *) (&cmd_ptr->PhysTBDArrayAddres);\r
+  ASSERT (cmd_ptr != NULL);\r
+  data_ptr  = (UINT8 *) cmd_ptr + sizeof (struct CB_Header);\r
 \r
   //\r
   // start the config data right after the command header\r
@@ -588,7 +589,8 @@ E100bSetupIAAddr (
   eaddrs    = (UINT16 *) AdapterInfo->CurrentNodeAddress;\r
 \r
   cmd_ptr   = GetFreeCB (AdapterInfo);\r
-  data_ptr  = (UINT16 *) (&cmd_ptr->PhysTBDArrayAddres);\r
+  ASSERT (cmd_ptr != NULL);\r
+  data_ptr  = (UINT16 *) ((UINT8 *) cmd_ptr +sizeof (struct CB_Header));\r
 \r
   //\r
   // AVOID a bug (?!) here by marking the command already completed.\r
@@ -1022,6 +1024,7 @@ E100bTransmit (
 \r
   tx_ptr_1  = (PXE_CPB_TRANSMIT *) (UINTN) cpb;\r
   tx_ptr_f  = (PXE_CPB_TRANSMIT_FRAGMENTS *) (UINTN) cpb;\r
+  Tmp_ptr = 0;\r
 \r
   //\r
   // stop reentrancy here\r
@@ -1387,7 +1390,7 @@ E100bReadEepromAndStationAddress (
   // in words\r
   //\r
   AdapterInfo->NVData_Len = eeprom_len = (UINT16) (1 << addr_len);\r
-  for (Index2 = 0, Index = 0; Index < eeprom_len; Index++) {\r
+  for (Index2 = 0, Index = 0; ((Index2 < PXE_MAC_LENGTH - 1) && (Index < eeprom_len)); Index++) {\r
     UINT16  value;\r
     value         = E100bReadEeprom (AdapterInfo, Index, addr_len);\r
     eedata[Index] = value;\r
@@ -2258,7 +2261,7 @@ E100bStatistics (
                   AdapterInfo->statistics->tx_lost_carrier;\r
 \r
   if (DBsize > sizeof db) {\r
-    DBsize = sizeof db;\r
+    DBsize = (UINT16) sizeof (db);\r
   }\r
 \r
   CopyMem ((VOID *) (UINTN) DBaddr, (VOID *) &db, (UINTN) DBsize);\r
index 7406b6d290d4be6bf0f974ee89edb5c57b1f4592..77931681e7b79a841482785d24496b9a5845748c 100644 (file)
@@ -882,7 +882,7 @@ AppendMac2DevPath (
 \r
   MacAddrNode.Header.Type       = MESSAGING_DEVICE_PATH;\r
   MacAddrNode.Header.SubType    = MSG_MAC_ADDR_DP;\r
-  MacAddrNode.Header.Length[0]  = sizeof (MacAddrNode);\r
+  MacAddrNode.Header.Length[0]  = (UINT8) sizeof (MacAddrNode);\r
   MacAddrNode.Header.Length[1]  = 0;\r
 \r
   //\r