[edk2-devel] [PATCH v3] MinPlatformPkg/TestPointCheckLib: Add check for pointers

Zhang, Shenglei posted 1 patch 4 years, 7 months ago
Failed in applying to current master (apply log)
There is a newer version of this series
.../Test/Library/TestPointCheckLib/DxeCheckBootVariable.c | 8 +++++++-
.../Test/Library/TestPointCheckLib/DxeCheckGcd.c          | 8 +++++---
2 files changed, 12 insertions(+), 4 deletions(-)
[edk2-devel] [PATCH v3] MinPlatformPkg/TestPointCheckLib: Add check for pointers
Posted by Zhang, Shenglei 4 years, 7 months ago
In DxeCheckBootVariable.c, add check for BootOrder and Variable
that return EFI_NOT_FOUND when they are NULL.
In DxeCheckGcd.c, add check for GcdIoMap to ensure it not NULL
when allocating memory to what it points to.

Cc: Michael Kubacki <michael.a.kubacki@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
---

v2: Update copyright

v3: Fix the coding style.

 .../Test/Library/TestPointCheckLib/DxeCheckBootVariable.c | 8 +++++++-
 .../Test/Library/TestPointCheckLib/DxeCheckGcd.c          | 8 +++++---
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckBootVariable.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckBootVariable.c
index 85bd5b3d..f658beb7 100644
--- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckBootVariable.c
+++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckBootVariable.c
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2017-2019, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -130,6 +130,9 @@ TestPointCheckLoadOptionVariable (
   for (ListIndex = 0; ListIndex < sizeof(mLoadOptionVariableList)/sizeof(mLoadOptionVariableList[0]); ListIndex++) {
     UnicodeSPrint (BootOrderName, sizeof(BootOrderName), L"%sOrder", mLoadOptionVariableList[ListIndex]);
     Status = GetVariable2 (BootOrderName, &gEfiGlobalVariableGuid, (VOID **)&BootOrder, &OrderSize);
+    if(BootOrder == NULL) {
+      return EFI_NOT_FOUND;
+    }
     if (EFI_ERROR(Status)) {
       continue;
     }
@@ -222,6 +225,9 @@ TestPointCheckKeyOptionVariable (
     for (Index = 0; ; Index++) {
       UnicodeSPrint (KeyOptionName, sizeof(KeyOptionName), L"%s%04x", mKeyOptionVariableList[ListIndex], Index);
       Status = GetVariable2 (KeyOptionName, &gEfiGlobalVariableGuid, &Variable, &Size);
+      if(Variable == NULL) {
+        return EFI_NOT_FOUND;
+      }
       if (!EFI_ERROR(Status)) {
         DumpKeyOption (KeyOptionName, Variable, Size);
       } else {
diff --git a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckGcd.c b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckGcd.c
index 82709d44..28ca8382 100644
--- a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckGcd.c
+++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckGcd.c
@@ -1,6 +1,6 @@
 /** @file
 
-Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2017-2019, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -241,11 +241,13 @@ TestPointDumpGcd (
       }
     }
     if (GcdMemoryMap != NULL) {
-      *GcdIoMap = AllocateCopyPool (NumberOfDescriptors * sizeof(EFI_GCD_IO_SPACE_DESCRIPTOR), IoMap);
+      if (GcdIoMap != NULL) {
+        *GcdIoMap = AllocateCopyPool (NumberOfDescriptors * sizeof(EFI_GCD_IO_SPACE_DESCRIPTOR), IoMap);
+      }
       *GcdIoMapNumberOfDescriptors = NumberOfDescriptors;
     }
   }
-  
+
   if (DumpPrint) {
     DEBUG ((DEBUG_INFO, "==== TestPointDumpGcd - Exit\n"));
   }
-- 
2.18.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#47441): https://edk2.groups.io/g/devel/message/47441
Mute This Topic: https://groups.io/mt/34183382/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH v3] MinPlatformPkg/TestPointCheckLib: Add check for pointers
Posted by Chiu, Chasel 4 years, 7 months ago
Feedbacks in below inline.

Thanks!
Chasel


> -----Original Message-----
> From: Zhang, Shenglei <shenglei.zhang@intel.com>
> Sent: Wednesday, September 18, 2019 9:54 AM
> To: devel@edk2.groups.io
> Cc: Kubacki, Michael A <michael.a.kubacki@intel.com>; Chiu, Chasel
> <chasel.chiu@intel.com>; Desimone, Nathaniel L
> <nathaniel.l.desimone@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: [PATCH v3] MinPlatformPkg/TestPointCheckLib: Add check for
> pointers
> 
> In DxeCheckBootVariable.c, add check for BootOrder and Variable that
> return EFI_NOT_FOUND when they are NULL.
> In DxeCheckGcd.c, add check for GcdIoMap to ensure it not NULL when
> allocating memory to what it points to.
> 
> Cc: Michael Kubacki <michael.a.kubacki@intel.com>
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
> ---
> 
> v2: Update copyright
> 
> v3: Fix the coding style.
> 
>  .../Test/Library/TestPointCheckLib/DxeCheckBootVariable.c | 8 +++++++-
>  .../Test/Library/TestPointCheckLib/DxeCheckGcd.c          | 8 +++++---
>  2 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git
> a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckB
> ootVariable.c
> b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckB
> ootVariable.c
> index 85bd5b3d..f658beb7 100644
> ---
> a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckB
> ootVariable.c
> +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCh
> +++ eckBootVariable.c
> @@ -1,6 +1,6 @@
>  /** @file
> 
> -Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2017-2019, Intel Corporation. All rights reserved.<BR>
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -130,6 +130,9 @@ TestPointCheckLoadOptionVariable (
>    for (ListIndex = 0; ListIndex <
> sizeof(mLoadOptionVariableList)/sizeof(mLoadOptionVariableList[0]);
> ListIndex++) {
>      UnicodeSPrint (BootOrderName, sizeof(BootOrderName), L"%sOrder",
> mLoadOptionVariableList[ListIndex]);
>      Status = GetVariable2 (BootOrderName, &gEfiGlobalVariableGuid,
> (VOID **)&BootOrder, &OrderSize);
> +    if(BootOrder == NULL) {
> +      return EFI_NOT_FOUND;
> +    }

I think we should continue the loop when BootOrder == NULL, we should not just return.
Suggest to combine the condition check in following line:

If (EFI_ERROR(Status) || (BootOrder == NULL)) {
  continue;
}






>      if (EFI_ERROR(Status)) {
>        continue;
>      }
> @@ -222,6 +225,9 @@ TestPointCheckKeyOptionVariable (
>      for (Index = 0; ; Index++) {
>        UnicodeSPrint (KeyOptionName, sizeof(KeyOptionName), L"%s%04x",
> mKeyOptionVariableList[ListIndex], Index);
>        Status = GetVariable2 (KeyOptionName, &gEfiGlobalVariableGuid,
> &Variable, &Size);
> +      if(Variable == NULL) {
> +        return EFI_NOT_FOUND;
> +      }


Same here, I think we should not return directly.
Combine the check in following line:

If (!EFI_ERROR(Status) && (Variable != NULL)) {
  DumpKeyOption (...);
else {
...





>        if (!EFI_ERROR(Status)) {
>          DumpKeyOption (KeyOptionName, Variable, Size);
>        } else {
> diff --git
> a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckG
> cd.c
> b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckG
> cd.c
> index 82709d44..28ca8382 100644
> ---
> a/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCheckG
> cd.c
> +++ b/Platform/Intel/MinPlatformPkg/Test/Library/TestPointCheckLib/DxeCh
> +++ eckGcd.c
> @@ -1,6 +1,6 @@
>  /** @file
> 
> -Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2017-2019, Intel Corporation. All rights reserved.<BR>
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -241,11 +241,13 @@ TestPointDumpGcd (
>        }
>      }
>      if (GcdMemoryMap != NULL) {
> -      *GcdIoMap = AllocateCopyPool (NumberOfDescriptors *
> sizeof(EFI_GCD_IO_SPACE_DESCRIPTOR), IoMap);
> +      if (GcdIoMap != NULL) {
> +        *GcdIoMap = AllocateCopyPool (NumberOfDescriptors *
> sizeof(EFI_GCD_IO_SPACE_DESCRIPTOR), IoMap);
> +      }
>        *GcdIoMapNumberOfDescriptors = NumberOfDescriptors;
>      }
>    }
> -
> +
>    if (DumpPrint) {
>      DEBUG ((DEBUG_INFO, "==== TestPointDumpGcd - Exit\n"));
>    }
> --
> 2.18.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#47459): https://edk2.groups.io/g/devel/message/47459
Mute This Topic: https://groups.io/mt/34183382/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-