[edk2] [Patch 2/5] NetworkPkg: Check allocated buffer pointer before use.

Fu Siyuan posted 5 patches 6 years, 11 months ago
[edk2] [Patch 2/5] NetworkPkg: Check allocated buffer pointer before use.
Posted by Fu Siyuan 6 years, 11 months ago
Cc: Ye Ting <ting.ye@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Cc: Wang Fan <fan.wang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
---
 NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c b/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
index f2239fd8c0..327b4cf1cf 100644
--- a/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
+++ b/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
@@ -2,7 +2,7 @@
   Functions implementation related with DHCPv6 for UefiPxeBc Driver.
 
   (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
-  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -2030,6 +2030,9 @@ PxeBcDhcp6CallBack (
       SelectAd   = &Private->OfferBuffer[Private->SelectIndex - 1].Dhcp6.Packet.Offer;
       *NewPacket = AllocateZeroPool (SelectAd->Size);
       ASSERT (*NewPacket != NULL);
+      if (*NewPacket == NULL) {
+        return EFI_ABORTED;
+      }
       CopyMem (*NewPacket, SelectAd, SelectAd->Size);
     }
     break;
-- 
2.13.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch 2/5] NetworkPkg: Check allocated buffer pointer before use.
Posted by Gary Lin 6 years, 11 months ago
On Tue, Jan 02, 2018 at 01:27:41PM +0800, Fu Siyuan wrote:
> Cc: Ye Ting <ting.ye@intel.com>
> Cc: Wu Jiaxin <jiaxin.wu@intel.com>
> Cc: Wang Fan <fan.wang@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
> ---
>  NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c b/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
> index f2239fd8c0..327b4cf1cf 100644
> --- a/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
> +++ b/NetworkPkg/UefiPxeBcDxe/PxeBcDhcp6.c
> @@ -2,7 +2,7 @@
>    Functions implementation related with DHCPv6 for UefiPxeBc Driver.
>  
>    (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
> -  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
>  
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD License
> @@ -2030,6 +2030,9 @@ PxeBcDhcp6CallBack (
>        SelectAd   = &Private->OfferBuffer[Private->SelectIndex - 1].Dhcp6.Packet.Offer;
>        *NewPacket = AllocateZeroPool (SelectAd->Size);
>        ASSERT (*NewPacket != NULL);
I guess this ASSERT can be removed since *NewPacket is checked later.

Gary Lin

> +      if (*NewPacket == NULL) {
> +        return EFI_ABORTED;
> +      }
>        CopyMem (*NewPacket, SelectAd, SelectAd->Size);
>      }
>      break;
> -- 
> 2.13.0.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
> 
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel