From e285199897e538523f762cb5b3900e81f872035a Mon Sep 17 00:00:00 2001 From: vanjeff Date: Fri, 8 Jan 2010 02:35:56 +0000 Subject: refine the code and add more security check. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9691 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c | 23 +++--- MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c | 92 +++++++++++------------ 2 files changed, 58 insertions(+), 57 deletions(-) (limited to 'MdeModulePkg/Universal/Network/Ip4Dxe') diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c index 5e297821a2..cccaab6dee 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Driver.c @@ -1,7 +1,7 @@ /** @file The driver binding and service binding protocol for IP4 driver. - -Copyright (c) 2005 - 2009, Intel Corporation.
+ +Copyright (c) 2005 - 2010, Intel Corporation.
All rights reserved. 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 @@ -27,7 +27,7 @@ EFI_DRIVER_BINDING_PROTOCOL gIp4DriverBinding = { This is the declaration of an EFI image entry point. This entry point is the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including both device drivers and bus drivers. - + The entry point for IP4 driver which install the driver binding and component name protocol on its image. @@ -446,6 +446,7 @@ Ip4DriverBindingStart ( if (EFI_ERROR (Status)) { return Status; } + ASSERT (IpSb != NULL); // // Install the Ip4ServiceBinding Protocol onto ControlerHandle @@ -507,7 +508,7 @@ FREE_SERVICE: restrictions for this service. DisconnectController() must follow these calling restrictions. If any other agent wishes to call Stop() it must also follow these calling restrictions. - + @param[in] This Protocol instance pointer. @param[in] ControllerHandle Handle of device to stop driver on @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number @@ -743,14 +744,14 @@ ON_ERROR: /** Creates a child handle and installs a protocol. - - The CreateChild() function installs a protocol on ChildHandle. - If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle. + + The CreateChild() function installs a protocol on ChildHandle. + If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle. If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle. @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance. @param ChildHandle Pointer to the handle of the child to create. If it is NULL, - then a new handle is created. If it is a pointer to an existing UEFI handle, + then a new handle is created. If it is a pointer to an existing UEFI handle, then the protocol is added to the existing UEFI handle. @retval EFI_SUCCES The protocol was added to ChildHandle. @@ -849,9 +850,9 @@ ON_ERROR: /** Destroys a child handle with a protocol installed on it. - - The DestroyChild() function does the opposite of CreateChild(). It removes a protocol - that was installed by CreateChild() from ChildHandle. If the removed protocol is the + + The DestroyChild() function does the opposite of CreateChild(). It removes a protocol + that was installed by CreateChild() from ChildHandle. If the removed protocol is the last protocol on ChildHandle, then ChildHandle is destroyed. @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance. diff --git a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c index 05fd96d634..ec545a6c54 100644 --- a/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c +++ b/MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Impl.c @@ -1,6 +1,6 @@ /** @file -Copyright (c) 2005 - 2009, Intel Corporation.
+Copyright (c) 2005 - 2010, Intel Corporation.
All rights reserved. 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 @@ -17,7 +17,7 @@ EFI_IPSEC_PROTOCOL *mIpSec = NULL; /** Gets the current operational settings for this instance of the EFI IPv4 Protocol driver. - + The GetModeData() function returns the current operational mode data for this driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This function is used optionally to retrieve the operational mode data of underlying @@ -41,10 +41,10 @@ EfiIp4GetModeData ( OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL, OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL ); - + /** Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance. - + The Configure() function is used to set, change, or reset the operational parameters and filter settings for this EFI IPv4 Protocol instance. Until these parameters have been set, no network traffic can be sent or received by this @@ -53,14 +53,14 @@ EfiIp4GetModeData ( parameters have been set again. Each EFI IPv4 Protocol instance can be started and stopped independently of each other by enabling or disabling their receive filter settings with the Configure() function. - + When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will be appended as an alias address into the addresses list in the EFI IPv4 Protocol driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL to retrieve the default IPv4 address if it is not available yet. Clients could frequently call GetModeData() to check the status to ensure that the default IPv4 address is ready. - + If operational parameters are reset or changed, any pending transmit and receive requests will be cancelled. Their completion token status will be set to EFI_ABORTED and their events will be signaled. @@ -91,14 +91,14 @@ EfiIp4Configure ( IN EFI_IP4_PROTOCOL *This, IN EFI_IP4_CONFIG_DATA *IpConfigData OPTIONAL ); - + /** Joins and leaves multicast groups. - + The Groups() function is used to join and leave multicast group sessions. Joining a group will enable reception of matching multicast packets. Leaving a group will disable the multicast packet reception. - + If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left. @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. @@ -129,25 +129,25 @@ EfiIp4Groups ( IN BOOLEAN JoinFlag, IN EFI_IPv4_ADDRESS *GroupAddress OPTIONAL ); - + /** Adds and deletes routing table entries. The Routes() function adds a route to or deletes a route from the routing table. - + Routes are determined by comparing the SubnetAddress with the destination IPv4 address arithmetically AND-ed with the SubnetMask. The gateway address must be on the same subnet as the configured station address. - + The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0. The default route matches all destination IPv4 addresses that do not match any other routes. - + A GatewayAddress that is zero is a nonroute. Packets are sent to the destination IP address if it can be found in the ARP cache or on the local subnet. One automatic nonroute entry will be inserted into the routing table for outgoing packets that are addressed to a local subnet (gateway address of 0.0.0.0). - + Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI IPv4 Protocol instances that use the default IPv4 address will also have copies of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these @@ -178,7 +178,7 @@ EfiIp4Groups ( @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE). @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when DeleteRoute is FALSE). - + **/ EFI_STATUS EFIAPI @@ -189,7 +189,7 @@ EfiIp4Routes ( IN EFI_IPv4_ADDRESS *SubnetMask, IN EFI_IPv4_ADDRESS *GatewayAddress ); - + /** Places outgoing data packets into the transmit queue. @@ -208,7 +208,7 @@ EfiIp4Routes ( @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event was already in the transmit queue. @retval EFI_NOT_READY The completion token could not be queued because the transmit - queue is full. + queue is full. @retval EFI_NOT_FOUND Not route is found to destination address. @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data. @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too @@ -225,13 +225,13 @@ EfiIp4Transmit ( IN EFI_IP4_PROTOCOL *This, IN EFI_IP4_COMPLETION_TOKEN *Token ); - + /** Places a receiving request into the receiving queue. - + The Receive() function places a completion token into the receive packet queue. This function is always asynchronous. - + The Token.Event field in the completion token must be filled in by the caller and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event @@ -264,10 +264,10 @@ EfiIp4Receive ( IN EFI_IP4_PROTOCOL *This, IN EFI_IP4_COMPLETION_TOKEN *Token ); - + /** Abort an asynchronous transmit or receive request. - + The Cancel() function is used to abort a pending transmit or receive request. If the token is in the transmit or receive request queues, after calling this function, Token->Status will be set to EFI_ABORTED and then Token->Event will @@ -300,15 +300,15 @@ EfiIp4Cancel ( IN EFI_IP4_PROTOCOL *This, IN EFI_IP4_COMPLETION_TOKEN *Token OPTIONAL ); - + /** Polls for incoming data packets and processes outgoing data packets. - + The Poll() function polls for incoming data packets and processes outgoing data packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll() function to increase the rate that data packets are moved between the communications device and the transmit and receive queues. - + In some systems the periodic timer event may not poll the underlying communications device fast enough to transmit and/or receive all data packets without missing incoming packets or dropping outgoing packets. Drivers and applications that are @@ -348,7 +348,7 @@ mEfiIp4ProtocolTemplete = { /** Gets the current operational settings for this instance of the EFI IPv4 Protocol driver. - + The GetModeData() function returns the current operational mode data for this driver instance. The data fields in EFI_IP4_MODE_DATA are read only. This function is used optionally to retrieve the operational mode data of underlying @@ -687,7 +687,7 @@ ON_EXIT: /** Request Ip4AutoConfigCallBackDpc as a DPC at TPL_CALLBACK. - + @param Event The event that is signalled. @param Context The IP4 service binding instance. @@ -1126,7 +1126,7 @@ Ip4StationAddressValid ( /** Assigns an IPv4 address and subnet mask to this EFI IPv4 Protocol driver instance. - + The Configure() function is used to set, change, or reset the operational parameters and filter settings for this EFI IPv4 Protocol instance. Until these parameters have been set, no network traffic can be sent or received by this @@ -1135,14 +1135,14 @@ Ip4StationAddressValid ( parameters have been set again. Each EFI IPv4 Protocol instance can be started and stopped independently of each other by enabling or disabling their receive filter settings with the Configure() function. - + When IpConfigData.UseDefaultAddress is set to FALSE, the new station address will be appended as an alias address into the addresses list in the EFI IPv4 Protocol driver. While set to TRUE, Configure() will trigger the EFI_IP4_CONFIG_PROTOCOL to retrieve the default IPv4 address if it is not available yet. Clients could frequently call GetModeData() to check the status to ensure that the default IPv4 address is ready. - + If operational parameters are reset or changed, any pending transmit and receive requests will be cancelled. Their completion token status will be set to EFI_ABORTED and their events will be signaled. @@ -1318,7 +1318,7 @@ Ip4Groups ( // host byte order // if (JoinFlag) { - // + // // When JoinFlag is TRUE, GroupAddress shouldn't be NULL. // ASSERT (GroupAddress != NULL); @@ -1386,11 +1386,11 @@ Ip4Groups ( /** Joins and leaves multicast groups. - + The Groups() function is used to join and leave multicast group sessions. Joining a group will enable reception of matching multicast packets. Leaving a group will disable the multicast packet reception. - + If JoinFlag is FALSE and GroupAddress is NULL, all joined groups will be left. @param[in] This Pointer to the EFI_IP4_PROTOCOL instance. @@ -1464,20 +1464,20 @@ ON_EXIT: Adds and deletes routing table entries. The Routes() function adds a route to or deletes a route from the routing table. - + Routes are determined by comparing the SubnetAddress with the destination IPv4 address arithmetically AND-ed with the SubnetMask. The gateway address must be on the same subnet as the configured station address. - + The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0. The default route matches all destination IPv4 addresses that do not match any other routes. - + A GatewayAddress that is zero is a nonroute. Packets are sent to the destination IP address if it can be found in the ARP cache or on the local subnet. One automatic nonroute entry will be inserted into the routing table for outgoing packets that are addressed to a local subnet (gateway address of 0.0.0.0). - + Each EFI IPv4 Protocol instance has its own independent routing table. Those EFI IPv4 Protocol instances that use the default IPv4 address will also have copies of the routing table that was provided by the EFI_IP4_CONFIG_PROTOCOL, and these @@ -1508,7 +1508,7 @@ ON_EXIT: @retval EFI_NOT_FOUND This route is not in the routing table (when DeleteRoute is TRUE). @retval EFI_ACCESS_DENIED The route is already defined in the routing table (when DeleteRoute is FALSE). - + **/ EFI_STATUS EFIAPI @@ -1693,7 +1693,7 @@ Ip4TxTokenValid ( // Check the source and gateway: they must be a valid unicast. // Gateway must also be on the connected network. // - if (TxData->OverrideData) { + if (TxData->OverrideData != NULL) { Override = TxData->OverrideData; CopyMem (&Src, &Override->SourceAddress, sizeof (IP4_ADDR)); @@ -1857,7 +1857,7 @@ Ip4OnPacketSent ( @retval EFI_ACCESS_DENIED The transmit completion token with the same Token.Event was already in the transmit queue. @retval EFI_NOT_READY The completion token could not be queued because the transmit - queue is full. + queue is full. @retval EFI_NOT_FOUND Not route is found to destination address. @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data. @retval EFI_BUFFER_TOO_SMALL Token.Packet.TxData.TotalDataLength is too @@ -1936,7 +1936,7 @@ EfiIp4Transmit ( CopyMem (&Head.Dst, &TxData->DestinationAddress, sizeof (IP4_ADDR)); Head.Dst = NTOHL (Head.Dst); - if (TxData->OverrideData) { + if (TxData->OverrideData != NULL) { Override = TxData->OverrideData; Head.Protocol = Override->Protocol; Head.Tos = Override->TypeOfService; @@ -2039,10 +2039,10 @@ ON_EXIT: /** Places a receiving request into the receiving queue. - + The Receive() function places a completion token into the receive packet queue. This function is always asynchronous. - + The Token.Event field in the completion token must be filled in by the caller and cannot be NULL. When the receive operation completes, the EFI IPv4 Protocol driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event @@ -2310,7 +2310,7 @@ Ip4Cancel ( /** Abort an asynchronous transmit or receive request. - + The Cancel() function is used to abort a pending transmit or receive request. If the token is in the transmit or receive request queues, after calling this function, Token->Status will be set to EFI_ABORTED and then Token->Event will @@ -2376,12 +2376,12 @@ ON_EXIT: /** Polls for incoming data packets and processes outgoing data packets. - + The Poll() function polls for incoming data packets and processes outgoing data packets. Network drivers and applications can call the EFI_IP4_PROTOCOL.Poll() function to increase the rate that data packets are moved between the communications device and the transmit and receive queues. - + In some systems the periodic timer event may not poll the underlying communications device fast enough to transmit and/or receive all data packets without missing incoming packets or dropping outgoing packets. Drivers and applications that are -- cgit v1.2.3