[PATCH v2] UnitTestFrameworkPkg/UnitTestLib: Check Suite pointer before use.


GuoMinJ
 

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2530

The Suite pointer is used before check if it is valid,
correct it to check the validation before use.

Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Sean Brogan <sean.brogan@...>
Cc: Bret Barkelew <Bret.Barkelew@...>
Signed-off-by: GuoMinJ <newexplorerj@...>
---
UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c | 6 +++---
UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
index fb247c59e7..b053e04959 100644
--- a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
+++ b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
@@ -33,13 +33,13 @@ RunTestSuite (
UNIT_TEST *Test;
UNIT_TEST_FRAMEWORK *ParentFramework;

- TestEntry = NULL;
- ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite->ParentFramework;
-
if (Suite == NULL) {
return EFI_INVALID_PARAMETER;
}

+ TestEntry = NULL;
+ ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite->ParentFramework;
+
DEBUG ((DEBUG_VERBOSE, "---------------------------------------------------------\n"));
DEBUG ((DEBUG_VERBOSE, "RUNNING TEST SUITE: %a\n", Suite->Title));
DEBUG ((DEBUG_VERBOSE, "---------------------------------------------------------\n"));
diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c b/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
index fd15991ea4..b136992d99 100644
--- a/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
+++ b/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
@@ -436,7 +436,6 @@ AddTestCase (

Status = EFI_SUCCESS;
Suite = (UNIT_TEST_SUITE *)SuiteHandle;
- ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite->ParentFramework;

//
// First, let's check to make sure that our parameters look good.
@@ -445,6 +444,7 @@ AddTestCase (
return EFI_INVALID_PARAMETER;
}

+ ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite->ParentFramework;
//
// Create the new entry.
NewTestEntry = AllocateZeroPool (sizeof( UNIT_TEST_LIST_ENTRY ));
--
2.17.1


Zhang, Shenglei
 

Reviewed-by: Shenglei Zhang <shenglei.zhang@...>

-----Original Message-----
From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
GuoMinJ
Sent: Thursday, March 5, 2020 2:18 PM
To: devel@edk2.groups.io
Cc: GuoMinJ <newexplorerj@...>; Kinney, Michael D
<michael.d.kinney@...>; Sean Brogan <sean.brogan@...>;
Bret Barkelew <Bret.Barkelew@...>
Subject: [edk2-devel] [PATCH v2] UnitTestFrameworkPkg/UnitTestLib: Check
Suite pointer before use.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2530

The Suite pointer is used before check if it is valid,
correct it to check the validation before use.

Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Sean Brogan <sean.brogan@...>
Cc: Bret Barkelew <Bret.Barkelew@...>
Signed-off-by: GuoMinJ <newexplorerj@...>
---
UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c | 6 +++---
UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
index fb247c59e7..b053e04959 100644
--- a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
+++ b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
@@ -33,13 +33,13 @@ RunTestSuite (
UNIT_TEST *Test;
UNIT_TEST_FRAMEWORK *ParentFramework;

- TestEntry = NULL;
- ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite->ParentFramework;
-
if (Suite == NULL) {
return EFI_INVALID_PARAMETER;
}

+ TestEntry = NULL;
+ ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite-
ParentFramework;
+
DEBUG ((DEBUG_VERBOSE, "--------------------------------------------------------
-\n"));
DEBUG ((DEBUG_VERBOSE, "RUNNING TEST SUITE: %a\n", Suite->Title));
DEBUG ((DEBUG_VERBOSE, "--------------------------------------------------------
-\n"));
diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
b/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
index fd15991ea4..b136992d99 100644
--- a/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
+++ b/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
@@ -436,7 +436,6 @@ AddTestCase (

Status = EFI_SUCCESS;
Suite = (UNIT_TEST_SUITE *)SuiteHandle;
- ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite->ParentFramework;

//
// First, let's check to make sure that our parameters look good.
@@ -445,6 +444,7 @@ AddTestCase (
return EFI_INVALID_PARAMETER;
}

+ ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite-
ParentFramework;
//
// Create the new entry.
NewTestEntry = AllocateZeroPool (sizeof( UNIT_TEST_LIST_ENTRY ));
--
2.17.1



Guomin Jiang
 

Hi Michael, Sean, Bret,

Could you review the patch?

Thanks

-----Original Message-----
From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
Zhang, Shenglei
Sent: Thursday, March 12, 2020 2:02 PM
To: devel@edk2.groups.io; newexplorerj@...
Cc: Kinney, Michael D <michael.d.kinney@...>; Sean Brogan
<sean.brogan@...>; Bret Barkelew
<Bret.Barkelew@...>
Subject: Re: [edk2-devel] [PATCH v2] UnitTestFrameworkPkg/UnitTestLib:
Check Suite pointer before use.

Reviewed-by: Shenglei Zhang <shenglei.zhang@...>

-----Original Message-----
From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
GuoMinJ
Sent: Thursday, March 5, 2020 2:18 PM
To: devel@edk2.groups.io
Cc: GuoMinJ <newexplorerj@...>; Kinney, Michael D
<michael.d.kinney@...>; Sean Brogan
<sean.brogan@...>;
Bret Barkelew <Bret.Barkelew@...>
Subject: [edk2-devel] [PATCH v2] UnitTestFrameworkPkg/UnitTestLib:
Check Suite pointer before use.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2530

The Suite pointer is used before check if it is valid, correct it to
check the validation before use.

Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Sean Brogan <sean.brogan@...>
Cc: Bret Barkelew <Bret.Barkelew@...>
Signed-off-by: GuoMinJ <newexplorerj@...>
---
UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c | 6 +++---
UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
index fb247c59e7..b053e04959 100644
--- a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
+++ b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
@@ -33,13 +33,13 @@ RunTestSuite (
UNIT_TEST *Test;
UNIT_TEST_FRAMEWORK *ParentFramework;

- TestEntry = NULL;
- ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite-
ParentFramework;
-
if (Suite == NULL) {
return EFI_INVALID_PARAMETER;
}

+ TestEntry = NULL;
+ ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite-
ParentFramework;
+
DEBUG ((DEBUG_VERBOSE,
"--------------------------------------------------------
-\n"));
DEBUG ((DEBUG_VERBOSE, "RUNNING TEST SUITE: %a\n", Suite->Title));
DEBUG ((DEBUG_VERBOSE,
"--------------------------------------------------------
-\n"));
diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
b/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
index fd15991ea4..b136992d99 100644
--- a/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
+++ b/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
@@ -436,7 +436,6 @@ AddTestCase (

Status = EFI_SUCCESS;
Suite = (UNIT_TEST_SUITE *)SuiteHandle;
- ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite-
ParentFramework;

//
// First, let's check to make sure that our parameters look good.
@@ -445,6 +444,7 @@ AddTestCase (
return EFI_INVALID_PARAMETER;
}

+ ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite-
ParentFramework;
//
// Create the new entry.
NewTestEntry = AllocateZeroPool (sizeof( UNIT_TEST_LIST_ENTRY ));
--
2.17.1




Michael D Kinney
 

Reviewed-by: Michael D Kinney <michael.d.kinney@...>

Mike

-----Original Message-----
From: Jiang, Guomin <guomin.jiang@...>
Sent: Sunday, March 22, 2020 11:08 PM
To: devel@edk2.groups.io; Zhang, Shenglei
<shenglei.zhang@...>; newexplorerj@...
Cc: Kinney, Michael D <michael.d.kinney@...>;
Sean Brogan <sean.brogan@...>; Bret Barkelew
<Bret.Barkelew@...>
Subject: RE: [edk2-devel] [PATCH v2]
UnitTestFrameworkPkg/UnitTestLib: Check Suite pointer
before use.

Hi Michael, Sean, Bret,

Could you review the patch?

Thanks

-----Original Message-----
From: devel@edk2.groups.io
[mailto:devel@edk2.groups.io] On Behalf Of
Zhang, Shenglei
Sent: Thursday, March 12, 2020 2:02 PM
To: devel@edk2.groups.io; newexplorerj@...
Cc: Kinney, Michael D <michael.d.kinney@...>;
Sean Brogan
<sean.brogan@...>; Bret Barkelew
<Bret.Barkelew@...>
Subject: Re: [edk2-devel] [PATCH v2]
UnitTestFrameworkPkg/UnitTestLib:
Check Suite pointer before use.

Reviewed-by: Shenglei Zhang
<shenglei.zhang@...>

-----Original Message-----
From: devel@edk2.groups.io
[mailto:devel@edk2.groups.io] On Behalf Of
GuoMinJ
Sent: Thursday, March 5, 2020 2:18 PM
To: devel@edk2.groups.io
Cc: GuoMinJ <newexplorerj@...>; Kinney,
Michael D
<michael.d.kinney@...>; Sean Brogan
<sean.brogan@...>;
Bret Barkelew <Bret.Barkelew@...>
Subject: [edk2-devel] [PATCH v2]
UnitTestFrameworkPkg/UnitTestLib:
Check Suite pointer before use.

REF:
https://bugzilla.tianocore.org/show_bug.cgi?id=2530

The Suite pointer is used before check if it is
valid, correct it to
check the validation before use.

Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Sean Brogan <sean.brogan@...>
Cc: Bret Barkelew <Bret.Barkelew@...>
Signed-off-by: GuoMinJ <newexplorerj@...>
---
UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
| 6 +++---
UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
| 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git
a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
index fb247c59e7..b053e04959 100644
---
a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
+++
b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
@@ -33,13 +33,13 @@ RunTestSuite (
UNIT_TEST *Test;
UNIT_TEST_FRAMEWORK *ParentFramework;

- TestEntry = NULL;
- ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite-
ParentFramework;
-
if (Suite == NULL) {
return EFI_INVALID_PARAMETER;
}

+ TestEntry = NULL;
+ ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite-
ParentFramework;
+
DEBUG ((DEBUG_VERBOSE,
"--------------------------------------------------
------
-\n"));
DEBUG ((DEBUG_VERBOSE, "RUNNING TEST SUITE:
%a\n", Suite->Title));
DEBUG ((DEBUG_VERBOSE,
"--------------------------------------------------
------
-\n"));
diff --git
a/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.
c
b/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.
c
index fd15991ea4..b136992d99 100644
---
a/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.
c
+++
b/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.
c
@@ -436,7 +436,6 @@ AddTestCase (

Status = EFI_SUCCESS;
Suite = (UNIT_TEST_SUITE
*)SuiteHandle;
- ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite-
ParentFramework;

//
// First, let's check to make sure that our
parameters look good.
@@ -445,6 +444,7 @@ AddTestCase (
return EFI_INVALID_PARAMETER;
}

+ ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite-
ParentFramework;
//
// Create the new entry.
NewTestEntry = AllocateZeroPool (sizeof(
UNIT_TEST_LIST_ENTRY ));
--
2.17.1




Bret Barkelew
 

Reviewed-by: Bret Barkelew <bret.barkelew@...>

 

- Bret

 


From: Kinney, Michael D <michael.d.kinney@...>
Sent: Monday, March 23, 2020 11:00:42 AM
To: Jiang, Guomin <guomin.jiang@...>; devel@edk2.groups.io <devel@edk2.groups.io>; Zhang, Shenglei <shenglei.zhang@...>; newexplorerj@... <newexplorerj@...>; Kinney, Michael D <michael.d.kinney@...>
Cc: Sean Brogan <sean.brogan@...>; Bret Barkelew <Bret.Barkelew@...>
Subject: [EXTERNAL] RE: [edk2-devel] [PATCH v2] UnitTestFrameworkPkg/UnitTestLib: Check Suite pointer before use.
 
Reviewed-by: Michael D Kinney <michael.d.kinney@...>

Mike

> -----Original Message-----
> From: Jiang, Guomin <guomin.jiang@...>
> Sent: Sunday, March 22, 2020 11:08 PM
> To: devel@edk2.groups.io; Zhang, Shenglei
> <shenglei.zhang@...>; newexplorerj@...
> Cc: Kinney, Michael D <michael.d.kinney@...>;
> Sean Brogan <sean.brogan@...>; Bret Barkelew
> <Bret.Barkelew@...>
> Subject: RE: [edk2-devel] [PATCH v2]
> UnitTestFrameworkPkg/UnitTestLib: Check Suite pointer
> before use.
>
> Hi Michael, Sean, Bret,
>
> Could you review the patch?
>
> Thanks
>
> > -----Original Message-----
> > From: devel@edk2.groups.io
> [mailto:devel@edk2.groups.io] On Behalf Of
> > Zhang, Shenglei
> > Sent: Thursday, March 12, 2020 2:02 PM
> > To: devel@edk2.groups.io; newexplorerj@...
> > Cc: Kinney, Michael D <michael.d.kinney@...>;
> Sean Brogan
> > <sean.brogan@...>; Bret Barkelew
> > <Bret.Barkelew@...>
> > Subject: Re: [edk2-devel] [PATCH v2]
> UnitTestFrameworkPkg/UnitTestLib:
> > Check Suite pointer before use.
> >
> > Reviewed-by: Shenglei Zhang
> <shenglei.zhang@...>
> >
> > > -----Original Message-----
> > > From: devel@edk2.groups.io
> [mailto:devel@edk2.groups.io] On Behalf Of
> > > GuoMinJ
> > > Sent: Thursday, March 5, 2020 2:18 PM
> > > To: devel@edk2.groups.io
> > > Cc: GuoMinJ <newexplorerj@...>; Kinney,
> Michael D
> > > <michael.d.kinney@...>; Sean Brogan
> > <sean.brogan@...>;
> > > Bret Barkelew <Bret.Barkelew@...>
> > > Subject: [edk2-devel] [PATCH v2]
> UnitTestFrameworkPkg/UnitTestLib:
> > > Check Suite pointer before use.
> > >
> > > REF:
> https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2530&amp;data=02%7C01%7CBret.Barkelew%40microsoft.com%7Cd0071fa41da24d2a4bd208d7cf541d73%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637205832511879282&amp;sdata=q0NPXM7RP90QhMdusDZGd9nn1VtA4w%2FYxZbFu0vvnkI%3D&amp;reserved=0
> > >
> > > The Suite pointer is used before check if it is
> valid, correct it to
> > > check the validation before use.
> > >
> > > Cc: Michael D Kinney <michael.d.kinney@...>
> > > Cc: Sean Brogan <sean.brogan@...>
> > > Cc: Bret Barkelew <Bret.Barkelew@...>
> > > Signed-off-by: GuoMinJ <newexplorerj@...>
> > > ---
> > >
> UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
> | 6 +++---
> > >
> UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c
> | 2 +-
> > >  2 files changed, 4 insertions(+), 4 deletions(-)
> > >
> > > diff --git
> a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
> > >
> b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
> > > index fb247c59e7..b053e04959 100644
> > > ---
> a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
> > > +++
> b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c
> > > @@ -33,13 +33,13 @@ RunTestSuite (
> > >    UNIT_TEST             *Test;
> > >    UNIT_TEST_FRAMEWORK   *ParentFramework;
> > >
> > > -  TestEntry       = NULL;
> > > -  ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite-
> > >ParentFramework;
> > > -
> > >    if (Suite == NULL) {
> > >      return EFI_INVALID_PARAMETER;
> > >    }
> > >
> > > +  TestEntry       = NULL;
> > > +  ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite-
> > > >ParentFramework;
> > > +
> > >    DEBUG ((DEBUG_VERBOSE,
> > > "--------------------------------------------------
> ------
> > > -\n"));
> > >    DEBUG ((DEBUG_VERBOSE, "RUNNING TEST SUITE:
> %a\n", Suite->Title));
> > >    DEBUG ((DEBUG_VERBOSE,
> > > "--------------------------------------------------
> ------
> > > -\n"));
> > > diff --git
> a/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.
> c
> > >
> b/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.
> c
> > > index fd15991ea4..b136992d99 100644
> > > ---
> a/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.
> c
> > > +++
> b/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.
> c
> > > @@ -436,7 +436,6 @@ AddTestCase (
> > >
> > >    Status          = EFI_SUCCESS;
> > >    Suite           = (UNIT_TEST_SUITE
> *)SuiteHandle;
> > > -  ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite-
> > >ParentFramework;
> > >
> > >    //
> > >    // First, let's check to make sure that our
> parameters look good.
> > > @@ -445,6 +444,7 @@ AddTestCase (
> > >      return EFI_INVALID_PARAMETER;
> > >    }
> > >
> > > +  ParentFramework = (UNIT_TEST_FRAMEWORK *)Suite-
> > > >ParentFramework;
> > >    //
> > >    // Create the new entry.
> > >    NewTestEntry = AllocateZeroPool (sizeof(
> UNIT_TEST_LIST_ENTRY ));
> > > --
> > > 2.17.1
> > >
> > >
> > >
> >
> >
> >