From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 29490740039 for ; Tue, 13 Feb 2024 19:41:12 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=yE0sQFWzswaDu+Ue96E+3XFEnvKogmMNKUFOSSEYqtk=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1707853270; v=1; b=VS9q/MsYWstAw0dZm7oPfdIlMcxNzNUAccz5loSiGdRCEmKhNSDgfPV0PIV7On08+oJ3TAVB a03P2c0koiujqeYZXilL0L+hRQTLQUna6SEpTis/EhGPXCqmLbOCCsc2yx7JU0xrJnuW+NNX66t vcICqfi+yQNPofrghfld/5AY= X-Received: by 127.0.0.2 with SMTP id IScVYY7687511xAG0EEjsOsS; Tue, 13 Feb 2024 11:41:10 -0800 X-Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mx.groups.io with SMTP id smtpd.web10.22884.1707853269443885042 for ; Tue, 13 Feb 2024 11:41:09 -0800 X-Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6da202aa138so3179829b3a.2 for ; Tue, 13 Feb 2024 11:41:09 -0800 (PST) X-Gm-Message-State: sMtvRy5akzQqIRvdTMipx75Ox7686176AA= X-Google-Smtp-Source: AGHT+IFOOwyg2KJZSFLpq9JNsGi+rgUuier3G1RLILPEM79QUwo8vnhfsnAVd+2if5aO/6NbhZ5QxQ== X-Received: by 2002:a05:6a20:e614:b0:1a0:6873:9bd2 with SMTP id my20-20020a056a20e61400b001a068739bd2mr279106pzb.2.1707853268161; Tue, 13 Feb 2024 11:41:08 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXw8JAeWwWFm/k8U+06JQvkoN2FQbWC8IXiYHpeddchBsvOWQaGMOMpYKMpZwmY7hKr67Xmdp5Cl/D2g/Ojk2EaAzli7QyFyMSAHl+4X/eqjd2hvRBQJrka2aLSz+HAC4jUXAopDDYdpDam4tefnw5Guz6s3Vstm0XaNvwV7h1ONw== X-Received: from localhost.localdomain ([131.107.147.247]) by smtp.gmail.com with ESMTPSA id ks6-20020a170903084600b001d9588f0714sm2436189plb.177.2024.02.13.11.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 11:41:07 -0800 (PST) From: "Doug Flick via groups.io" To: devel@edk2.groups.io Cc: Doug Flick , Saloni Kasbekar , Zachary Clark-williams , "Doug Flick [MSFT]" Subject: [edk2-devel] [PATCH v2 2/4] NetworkPkg: Dhcp6Dxe: Removes duplicate check and replaces with macro Date: Tue, 13 Feb 2024 10:46:01 -0800 Message-Id: <20240213184603.2985-3-doug.edk2@gmail.com> In-Reply-To: <20240213184603.2985-1-doug.edk2@gmail.com> References: <20240213184603.2985-1-doug.edk2@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,dougflick@microsoft.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="VS9q/MsY"; dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io From: Doug Flick Removes duplicate check after merge > > // > // Verify the PacketCursor is within the packet > // > if ( (*PacketCursor < Packet->Dhcp6.Option) > || (*PacketCursor >=3D Packet->Dhcp6.Option + (Packet->Size - sizeof (EFI_DHCP6_HEADER)))) > { > return EFI_INVALID_PARAMETER; > } > Converts the check to a macro and replaces all instances of the check with the macro Cc: Saloni Kasbekar Cc: Zachary Clark-williams Signed-off-by: Doug Flick [MSFT] --- NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c | 46 +++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c b/NetworkPkg/Dhcp6Dxe/Dhcp6= Utility.c index 705c665c519d..e4e072562296 100644 --- a/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c +++ b/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c @@ -10,6 +10,16 @@ =0D #include "Dhcp6Impl.h"=0D =0D +//=0D +// Verifies the packet cursor is within the packet=0D +// otherwise it is invalid=0D +//=0D +#define IS_INVALID_PACKET_CURSOR(PacketCursor, Packet) \=0D + (((*PacketCursor) < (Packet)->Dhcp6.Option) || \=0D + ((*PacketCursor) >=3D (Packet)->Dhcp6.Option + ((Packet)->Size - sizeof= (EFI_DHCP6_HEADER))) \=0D + ) = \=0D +=0D +=0D /**=0D Generate client Duid in the format of Duid-llt.=0D =0D @@ -638,9 +648,7 @@ Dhcp6AppendOption ( //=0D // Verify the PacketCursor is within the packet=0D //=0D - if ( (*PacketCursor < Packet->Dhcp6.Option)=0D - || (*PacketCursor >=3D Packet->Dhcp6.Option + (Packet->Size - sizeof = (EFI_DHCP6_HEADER))))=0D - {=0D + if (IS_INVALID_PACKET_CURSOR (PacketCursor, Packet)) {=0D return EFI_INVALID_PARAMETER;=0D }=0D =0D @@ -657,15 +665,6 @@ Dhcp6AppendOption ( return EFI_BUFFER_TOO_SMALL;=0D }=0D =0D - //=0D - // Verify the PacketCursor is within the packet=0D - //=0D - if ( (*PacketCursor < Packet->Dhcp6.Option)=0D - || (*PacketCursor >=3D Packet->Dhcp6.Option + (Packet->Size - sizeof = (EFI_DHCP6_HEADER))))=0D - {=0D - return EFI_INVALID_PARAMETER;=0D - }=0D -=0D WriteUnaligned16 ((UINT16 *)*PacketCursor, OptType);=0D *PacketCursor +=3D DHCP6_SIZE_OF_OPT_CODE;=0D WriteUnaligned16 ((UINT16 *)*PacketCursor, OptLen);=0D @@ -744,9 +743,7 @@ Dhcp6AppendIaAddrOption ( //=0D // Verify the PacketCursor is within the packet=0D //=0D - if ( (*PacketCursor < Packet->Dhcp6.Option)=0D - || (*PacketCursor >=3D Packet->Dhcp6.Option + (Packet->Size - sizeof = (EFI_DHCP6_HEADER))))=0D - {=0D + if (IS_INVALID_PACKET_CURSOR (PacketCursor, Packet)) {=0D return EFI_INVALID_PARAMETER;=0D }=0D =0D @@ -877,9 +874,7 @@ Dhcp6AppendIaOption ( //=0D // Verify the PacketCursor is within the packet=0D //=0D - if ( (*PacketCursor < Packet->Dhcp6.Option)=0D - || (*PacketCursor >=3D Packet->Dhcp6.Option + (Packet->Size - sizeof = (EFI_DHCP6_HEADER))))=0D - {=0D + if (IS_INVALID_PACKET_CURSOR (PacketCursor, Packet)) {=0D return EFI_INVALID_PARAMETER;=0D }=0D =0D @@ -940,16 +935,16 @@ Dhcp6AppendIaOption ( }=0D }=0D =0D + //=0D + // Update the packet length=0D + //=0D + Packet->Length +=3D BytesNeeded;=0D +=0D //=0D // Fill the value of Ia option length=0D //=0D *Len =3D HTONS ((UINT16)(*PacketCursor - (UINT8 *)Len - 2));=0D =0D - //=0D - // Update the packet length=0D - //=0D - Packet->Length +=3D BytesNeeded;=0D -=0D return EFI_SUCCESS;=0D }=0D =0D @@ -957,6 +952,7 @@ Dhcp6AppendIaOption ( Append the appointed Elapsed time option to Buf, and move Buf to the end= .=0D =0D @param[in, out] Packet A pointer to the packet, on success Packet= ->Length=0D + will be updated.=0D @param[in, out] PacketCursor The pointer in the packet, on success Pack= etCursor=0D will be moved to the end of the option.=0D @param[in] Instance The pointer to the Dhcp6 instance.=0D @@ -1012,9 +1008,7 @@ Dhcp6AppendETOption ( //=0D // Verify the PacketCursor is within the packet=0D //=0D - if ( (*PacketCursor < Packet->Dhcp6.Option)=0D - || (*PacketCursor >=3D Packet->Dhcp6.Option + (Packet->Size - sizeof = (EFI_DHCP6_HEADER))))=0D - {=0D + if (IS_INVALID_PACKET_CURSOR (PacketCursor, Packet)) {=0D return EFI_INVALID_PARAMETER;=0D }=0D =0D --=20 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115408): https://edk2.groups.io/g/devel/message/115408 Mute This Topic: https://groups.io/mt/104339707/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-