Hi Siyuan,

Maybe we can add more check for the Len to return directly, what do you think?

  if (Len == 0) {
    return 0;
  }

> +  if (Nbuf->TotalSize == 0) {
> +    return 0;
> +  }

Thanks,
Jiaxin


> -----Original Message-----
> From: Fu, Siyuan
> Sent: Wednesday, September 20, 2017 11:24 AM
> To: edk2-devel@lists.01.org
> Cc: Wu, Jiaxin <jiaxin...@intel.com>; Ye, Ting <ting...@intel.com>; Michael
> Turner <michael.tur...@microsoft.com>
> Subject: [Patch] MdeModulePkg/DxeNetLib: Check the actual packet size
> before trim data from Nbuf.
> 
> In NetbufTrim() function, the NetBuf TotalSize should be checked with 0
> before
> making the trim operation, otherwise the function will fall into infinite 
> loop.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Fu Siyuan <siyuan...@intel.com>
> Cc: Wu Jiaxin <jiaxin...@intel.com>
> Cc: Ye Ting <ting...@intel.com>
> Cc: Michael Turner <michael.tur...@microsoft.com>
> ---
>  MdeModulePkg/Library/DxeNetLib/NetBuffer.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/MdeModulePkg/Library/DxeNetLib/NetBuffer.c
> b/MdeModulePkg/Library/DxeNetLib/NetBuffer.c
> index 95cb71714b..25fc78e49e 100644
> --- a/MdeModulePkg/Library/DxeNetLib/NetBuffer.c
> +++ b/MdeModulePkg/Library/DxeNetLib/NetBuffer.c
> @@ -1175,6 +1175,10 @@ NetbufTrim (
> 
>    NET_CHECK_SIGNATURE (Nbuf, NET_BUF_SIGNATURE);
> 
> +  if (Nbuf->TotalSize == 0) {
> +    return 0;
> +  }
> +
>    if (Len > Nbuf->TotalSize) {
>      Len = Nbuf->TotalSize;
>    }
> --
> 2.13.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to