X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=NetworkPkg%2FHttpBootDxe%2FHttpBootDhcp4.c;h=229e6cb0ec6a73791a9c25a55ff30cb90caf31fc;hb=1ba4a4df3972cec30b2aa44ff9ff53e5f5eeddc1;hp=a47a8f494f9ec1cf8c4f0678dddfb429a49a2a07;hpb=142c00c3d659a6d5d66416385b4c93fd9a9f10e6;p=mirror_edk2.git diff --git a/NetworkPkg/HttpBootDxe/HttpBootDhcp4.c b/NetworkPkg/HttpBootDxe/HttpBootDhcp4.c index a47a8f494f..229e6cb0ec 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootDhcp4.c +++ b/NetworkPkg/HttpBootDxe/HttpBootDhcp4.c @@ -1,7 +1,7 @@ /** @file Functions implementation related with DHCPv4 for HTTP boot driver. -Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 2017, 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 that accompanies this distribution. The full text of the license may be found at @@ -220,17 +220,24 @@ HttpBootParseDhcp4Options ( @param[in] Dst Pointer to the cache buffer for DHCPv4 packet. @param[in] Src Pointer to the DHCPv4 packet to be cached. + @retval EFI_SUCCESS Packet is copied. + @retval EFI_BUFFER_TOO_SMALL Cache buffer is not big enough to hold the packet. + **/ -VOID +EFI_STATUS HttpBootCacheDhcp4Packet ( IN EFI_DHCP4_PACKET *Dst, IN EFI_DHCP4_PACKET *Src ) { - ASSERT (Dst->Size >= Src->Length); + if (Dst->Size < Src->Length) { + return EFI_BUFFER_TOO_SMALL; + } CopyMem (&Dst->Dhcp4, &Src->Dhcp4, Src->Length); Dst->Length = Src->Length; + + return EFI_SUCCESS; } /** @@ -325,8 +332,8 @@ HttpBootParseDhcp4Packet ( // The offer with "HTTPClient" is a Http offer. // Option = Options[HTTP_BOOT_DHCP4_TAG_INDEX_CLASS_ID]; - if ((Option != NULL) && (Option->Length >= 9) && - (CompareMem (Option->Data, DEFAULT_CLASS_ID_DATA, 9) == 0)) { + if ((Option != NULL) && (Option->Length >= 10) && + (CompareMem (Option->Data, DEFAULT_CLASS_ID_DATA, 10) == 0)) { IsHttpOffer = TRUE; } @@ -415,6 +422,9 @@ HttpBootParseDhcp4Packet ( if (!IsProxyOffer) { OfferType = IsDnsOffer ? HttpOfferTypeDhcpDns : HttpOfferTypeDhcpOnly; } else { + if (Cache4->UriParser != NULL) { + FreePool (Cache4->UriParser); + } return EFI_DEVICE_ERROR; } } @@ -429,8 +439,10 @@ HttpBootParseDhcp4Packet ( @param[in] Private Pointer to HTTP boot driver private data. @param[in] RcvdOffer Pointer to the received offer packet. + @retval EFI_SUCCESS Cache and parse the packet successfully. + @retval Others Operation failed. **/ -VOID +EFI_STATUS HttpBootCacheDhcp4Offer ( IN HTTP_BOOT_PRIVATE_DATA *Private, IN EFI_DHCP4_PACKET *RcvdOffer @@ -439,6 +451,7 @@ HttpBootCacheDhcp4Offer ( HTTP_BOOT_DHCP4_PACKET_CACHE *Cache4; EFI_DHCP4_PACKET *Offer; HTTP_BOOT_OFFER_TYPE OfferType; + EFI_STATUS Status; ASSERT (Private->OfferNum < HTTP_BOOT_OFFER_MAX_NUM); Cache4 = &Private->OfferBuffer[Private->OfferNum].Dhcp4; @@ -447,13 +460,16 @@ HttpBootCacheDhcp4Offer ( // // Cache the content of DHCPv4 packet firstly. // - HttpBootCacheDhcp4Packet (Offer, RcvdOffer); + Status = HttpBootCacheDhcp4Packet (Offer, RcvdOffer); + if (EFI_ERROR (Status)) { + return Status; + } // // Validate the DHCPv4 packet, and parse the options and offer type. // if (EFI_ERROR (HttpBootParseDhcp4Packet (Cache4))) { - return; + return EFI_ABORTED; } // @@ -465,6 +481,8 @@ HttpBootCacheDhcp4Offer ( Private->OfferIndex[OfferType][Private->OfferCount[OfferType]] = Private->OfferNum; Private->OfferCount[OfferType]++; Private->OfferNum++; + + return EFI_SUCCESS; } /** @@ -594,8 +612,13 @@ HttpBootDhcp4CallBack ( EFI_DHCP4_PACKET_OPTION *MaxMsgSize; UINT16 Value; EFI_STATUS Status; + BOOLEAN Received; - if ((Dhcp4Event != Dhcp4RcvdOffer) && (Dhcp4Event != Dhcp4SelectOffer)) { + if ((Dhcp4Event != Dhcp4SendDiscover) && + (Dhcp4Event != Dhcp4RcvdOffer) && + (Dhcp4Event != Dhcp4SendRequest) && + (Dhcp4Event != Dhcp4RcvdAck) && + (Dhcp4Event != Dhcp4SelectOffer)) { return EFI_SUCCESS; } @@ -613,15 +636,39 @@ HttpBootDhcp4CallBack ( Value = HTONS (HTTP_BOOT_DHCP4_PACKET_MAX_SIZE); CopyMem (MaxMsgSize->Data, &Value, sizeof (Value)); } + + // + // Callback to user if any packets sent or received. + // + if (Private->HttpBootCallback != NULL && Dhcp4Event != Dhcp4SelectOffer) { + Received = (BOOLEAN) (Dhcp4Event == Dhcp4RcvdOffer || Dhcp4Event == Dhcp4RcvdAck); + Status = Private->HttpBootCallback->Callback ( + Private->HttpBootCallback, + HttpBootDhcp4, + Received, + Packet->Length, + &Packet->Dhcp4 + ); + if (EFI_ERROR (Status)) { + return EFI_ABORTED; + } + } Status = EFI_SUCCESS; switch (Dhcp4Event) { case Dhcp4RcvdOffer: Status = EFI_NOT_READY; + if (Packet->Length > HTTP_BOOT_DHCP4_PACKET_MAX_SIZE) { + // + // Ignore the incoming packets which exceed the maximum length. + // + break; + } if (Private->OfferNum < HTTP_BOOT_OFFER_MAX_NUM) { // // Cache the DHCPv4 offers to OfferBuffer[] for select later, and record // the OfferIndex and OfferCount. + // If error happens, just ignore this packet and continue to wait more offer. // HttpBootCacheDhcp4Offer (Private, Packet); }