NetworkPkg: Replace ASSERT with error return code in PXE and HTTP boot driver.
This patch remove the ASSERT when receive a DHCP packet large than the maximum cache buffer size. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Fu Siyuan <siyuan.fu@intel.com> Reviewed-by: Ye Ting <ting.ye@intel.com> Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
This commit is contained in:
@@ -181,17 +181,24 @@ PxeBcBuildDhcp6Options (
|
||||
@param[in] Dst The pointer to the cache buffer for DHCPv6 packet.
|
||||
@param[in] Src The pointer to the DHCPv6 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
|
||||
PxeBcCacheDhcp6Packet (
|
||||
IN EFI_DHCP6_PACKET *Dst,
|
||||
IN EFI_DHCP6_PACKET *Src
|
||||
)
|
||||
{
|
||||
ASSERT (Dst->Size >= Src->Length);
|
||||
if (Dst->Size < Src->Length) {
|
||||
return EFI_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
CopyMem (&Dst->Dhcp6, &Src->Dhcp6, Src->Length);
|
||||
Dst->Length = Src->Length;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -749,8 +756,11 @@ PxeBcParseDhcp6Packet (
|
||||
@param[in] Ack The pointer to the DHCPv6 ack packet.
|
||||
@param[in] Verified If TRUE, parse the ACK packet and store info into mode data.
|
||||
|
||||
@retval EFI_SUCCESS Cache and parse the packet successfully.
|
||||
@retval EFI_BUFFER_TOO_SMALL Cache buffer is not big enough to hold the packet.
|
||||
|
||||
**/
|
||||
VOID
|
||||
EFI_STATUS
|
||||
PxeBcCopyDhcp6Ack (
|
||||
IN PXEBC_PRIVATE_DATA *Private,
|
||||
IN EFI_DHCP6_PACKET *Ack,
|
||||
@@ -758,10 +768,14 @@ PxeBcCopyDhcp6Ack (
|
||||
)
|
||||
{
|
||||
EFI_PXE_BASE_CODE_MODE *Mode;
|
||||
EFI_STATUS Status;
|
||||
|
||||
Mode = Private->PxeBc.Mode;
|
||||
|
||||
PxeBcCacheDhcp6Packet (&Private->DhcpAck.Dhcp6.Packet.Ack, Ack);
|
||||
Status = PxeBcCacheDhcp6Packet (&Private->DhcpAck.Dhcp6.Packet.Ack, Ack);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
if (Verified) {
|
||||
//
|
||||
@@ -771,6 +785,8 @@ PxeBcCopyDhcp6Ack (
|
||||
CopyMem (&Mode->DhcpAck.Dhcpv6, &Ack->Dhcp6, Ack->Length);
|
||||
Mode->DhcpAckReceived = TRUE;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -780,8 +796,11 @@ PxeBcCopyDhcp6Ack (
|
||||
@param[in] Private The pointer to PxeBc private data.
|
||||
@param[in] OfferIndex The received order of offer packets.
|
||||
|
||||
@retval EFI_SUCCESS Cache and parse the packet successfully.
|
||||
@retval EFI_BUFFER_TOO_SMALL Cache buffer is not big enough to hold the packet.
|
||||
|
||||
**/
|
||||
VOID
|
||||
EFI_STATUS
|
||||
PxeBcCopyDhcp6Proxy (
|
||||
IN PXEBC_PRIVATE_DATA *Private,
|
||||
IN UINT32 OfferIndex
|
||||
@@ -789,6 +808,7 @@ PxeBcCopyDhcp6Proxy (
|
||||
{
|
||||
EFI_PXE_BASE_CODE_MODE *Mode;
|
||||
EFI_DHCP6_PACKET *Offer;
|
||||
EFI_STATUS Status;
|
||||
|
||||
ASSERT (OfferIndex < Private->OfferNum);
|
||||
ASSERT (OfferIndex < PXEBC_OFFER_MAX_NUM);
|
||||
@@ -799,7 +819,10 @@ PxeBcCopyDhcp6Proxy (
|
||||
//
|
||||
// Cache the proxy offer packet and parse it.
|
||||
//
|
||||
PxeBcCacheDhcp6Packet (&Private->ProxyOffer.Dhcp6.Packet.Offer, Offer);
|
||||
Status = PxeBcCacheDhcp6Packet (&Private->ProxyOffer.Dhcp6.Packet.Offer, Offer);
|
||||
if (EFI_ERROR(Status)) {
|
||||
return Status;
|
||||
}
|
||||
PxeBcParseDhcp6Packet (&Private->ProxyOffer.Dhcp6);
|
||||
|
||||
//
|
||||
@@ -807,6 +830,8 @@ PxeBcCopyDhcp6Proxy (
|
||||
//
|
||||
CopyMem (&Mode->ProxyOffer.Dhcpv6, &Offer->Dhcp6, Offer->Length);
|
||||
Mode->ProxyOfferReceived = TRUE;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1121,8 +1146,10 @@ PxeBcRetryDhcp6Binl (
|
||||
@param[in] Private The pointer to PXEBC_PRIVATE_DATA.
|
||||
@param[in] RcvdOffer The pointer to the received offer packet.
|
||||
|
||||
@retval EFI_SUCCESS Cache and parse the packet successfully.
|
||||
@retval Others Operation failed.
|
||||
**/
|
||||
VOID
|
||||
EFI_STATUS
|
||||
PxeBcCacheDhcp6Offer (
|
||||
IN PXEBC_PRIVATE_DATA *Private,
|
||||
IN EFI_DHCP6_PACKET *RcvdOffer
|
||||
@@ -1131,6 +1158,7 @@ PxeBcCacheDhcp6Offer (
|
||||
PXEBC_DHCP6_PACKET_CACHE *Cache6;
|
||||
EFI_DHCP6_PACKET *Offer;
|
||||
PXEBC_OFFER_TYPE OfferType;
|
||||
EFI_STATUS Status;
|
||||
|
||||
Cache6 = &Private->OfferBuffer[Private->OfferNum].Dhcp6;
|
||||
Offer = &Cache6->Packet.Offer;
|
||||
@@ -1138,13 +1166,16 @@ PxeBcCacheDhcp6Offer (
|
||||
//
|
||||
// Cache the content of DHCPv6 packet firstly.
|
||||
//
|
||||
PxeBcCacheDhcp6Packet (Offer, RcvdOffer);
|
||||
Status = PxeBcCacheDhcp6Packet (Offer, RcvdOffer);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate the DHCPv6 packet, and parse the options and offer type.
|
||||
//
|
||||
if (EFI_ERROR (PxeBcParseDhcp6Packet (Cache6))) {
|
||||
return ;
|
||||
return EFI_ABORTED;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1173,7 +1204,7 @@ PxeBcCacheDhcp6Offer (
|
||||
Private->OfferIndex[OfferType][0] = Private->OfferNum;
|
||||
Private->OfferCount[OfferType] = 1;
|
||||
} else {
|
||||
return;
|
||||
return EFI_ABORTED;
|
||||
}
|
||||
} else {
|
||||
//
|
||||
@@ -1184,6 +1215,8 @@ PxeBcCacheDhcp6Offer (
|
||||
}
|
||||
|
||||
Private->OfferNum++;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -1301,6 +1334,7 @@ PxeBcSelectDhcp6Offer (
|
||||
@retval EFI_SUCCESS Handled the DHCPv6 offer packet successfully.
|
||||
@retval EFI_NO_RESPONSE No response to the following request packet.
|
||||
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
|
||||
@retval EFI_BUFFER_TOO_SMALL Can't cache the offer pacet.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
@@ -1410,7 +1444,7 @@ PxeBcHandleDhcp6Offer (
|
||||
//
|
||||
// Success to try to request by a ProxyPxe10 or ProxyWfm11a offer, copy and parse it.
|
||||
//
|
||||
PxeBcCopyDhcp6Proxy (Private, ProxyIndex);
|
||||
Status = PxeBcCopyDhcp6Proxy (Private, ProxyIndex);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
@@ -1424,7 +1458,7 @@ PxeBcHandleDhcp6Offer (
|
||||
//
|
||||
// All PXE boot information is ready by now.
|
||||
//
|
||||
PxeBcCopyDhcp6Ack (Private, &Private->DhcpAck.Dhcp6.Packet.Ack, TRUE);
|
||||
Status = PxeBcCopyDhcp6Ack (Private, &Private->DhcpAck.Dhcp6.Packet.Ack, TRUE);
|
||||
Private->PxeBc.Mode->DhcpDiscoverValid = TRUE;
|
||||
}
|
||||
|
||||
@@ -1997,19 +2031,15 @@ PxeBcDhcp6CallBack (
|
||||
break;
|
||||
|
||||
case Dhcp6RcvdReply:
|
||||
if (Packet->Length > PXEBC_DHCP6_PACKET_MAX_SIZE) {
|
||||
//
|
||||
// Abort the DHCP if the Peply packet exceeds the maximum length.
|
||||
//
|
||||
Status = EFI_ABORTED;
|
||||
break;
|
||||
}
|
||||
//
|
||||
// Cache the dhcp ack to Private->Dhcp6Ack, but it's not the final ack in mode data
|
||||
// without verification.
|
||||
//
|
||||
ASSERT (Private->SelectIndex != 0);
|
||||
PxeBcCopyDhcp6Ack (Private, Packet, FALSE);
|
||||
Status = PxeBcCopyDhcp6Ack (Private, Packet, FALSE);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Status = EFI_ABORTED;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Reference in New Issue
Block a user