[edk2] [patch] MdeModulePkg/PerfLib: Add NULL pointer check for "Token"

Dandan Bi posted 1 patch 6 years, 2 months ago
Failed in applying to current master (apply log)
MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c | 6 +++++-
MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c         | 6 +++++-
MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c | 6 +++++-
3 files changed, 15 insertions(+), 3 deletions(-)
[edk2] [patch] MdeModulePkg/PerfLib: Add NULL pointer check for "Token"
Posted by Dandan Bi 6 years, 2 months ago
"Token" is passed through the perf entry, it's may be NULL.
So we need to add NULL pointer check before reference it.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
---
 MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c | 6 +++++-
 MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c         | 6 +++++-
 MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c | 6 +++++-
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
index 8363b0e..9b3224e 100644
--- a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
+++ b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
@@ -113,10 +113,14 @@ Check whether the Token is a known one which is uesed by core.
 BOOLEAN
 IsKnownTokens (
   IN CONST CHAR8  *Token
   )
 {
+  if (Token == NULL) {
+    return FALSE;
+  }
+
   if (AsciiStrCmp (Token, SEC_TOK) == 0 ||
       AsciiStrCmp (Token, PEI_TOK) == 0 ||
       AsciiStrCmp (Token, DXE_TOK) == 0 ||
       AsciiStrCmp (Token, BDS_TOK) == 0 ||
       AsciiStrCmp (Token, DRIVERBINDING_START_TOK) == 0 ||
@@ -845,11 +849,11 @@ InsertFpdtMeasurement (
     return Status;
   }
 
   //
   // If PERF_START()/PERF_END() have specified the ProgressID,it has high priority.
-  // !!! Note: If the Pref is not the known Token used in the core but have same
+  // !!! Note: If the Perf is not the known Token used in the core but have same
   // ID with the core Token, this case will not be supported.
   // And in currtnt usage mode, for the unkown ID, there is a general rule:
   // If it is start pref: the lower 4 bits of the ID should be 0.
   // If it is end pref: the lower 4 bits of the ID should not be 0.
   // If input ID doesn't follow the rule, we will adjust it.
diff --git a/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c b/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c
index 79b67e8..f770a35 100644
--- a/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c
+++ b/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c
@@ -47,10 +47,14 @@ Check whether the Token is a known one which is uesed by core.
 BOOLEAN
 IsKnownTokens (
   IN CONST CHAR8  *Token
   )
 {
+  if (Token == NULL) {
+    return FALSE;
+  }
+
   if (AsciiStrCmp (Token, SEC_TOK) == 0 ||
       AsciiStrCmp (Token, PEI_TOK) == 0 ||
       AsciiStrCmp (Token, DXE_TOK) == 0 ||
       AsciiStrCmp (Token, BDS_TOK) == 0 ||
       AsciiStrCmp (Token, DRIVERBINDING_START_TOK) == 0 ||
@@ -264,11 +268,11 @@ InsertPeiFpdtMeasurement (
     return Status;
   }
 
   //
   // If PERF_START()/PERF_END() have specified the ProgressID,it has high priority.
-  // !!! Note: If the Pref is not the known Token used in the core but have same
+  // !!! Note: If the Perf is not the known Token used in the core but have same
   // ID with the core Token, this case will not be supported.
   // And in currtnt usage mode, for the unkown ID, there is a general rule:
   // If it is start pref: the lower 4 bits of the ID should be 0.
   // If it is end pref: the lower 4 bits of the ID should not be 0.
   // If input ID doesn't follow the rule, we will adjust it.
diff --git a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c
index 2834a68..dbc1166 100644
--- a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c
+++ b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c
@@ -83,10 +83,14 @@ Check whether the Token is a known one which is uesed by core.
 BOOLEAN
 IsKnownTokens (
   IN CONST CHAR8  *Token
   )
 {
+  if (Token == NULL) {
+    return FALSE;
+  }
+
   if (AsciiStrCmp (Token, SEC_TOK) == 0 ||
       AsciiStrCmp (Token, PEI_TOK) == 0 ||
       AsciiStrCmp (Token, DXE_TOK) == 0 ||
       AsciiStrCmp (Token, BDS_TOK) == 0 ||
       AsciiStrCmp (Token, DRIVERBINDING_START_TOK) == 0 ||
@@ -495,11 +499,11 @@ InsertFpdtMeasurement (
     return Status;
   }
 
   //
   // If PERF_START()/PERF_END() have specified the ProgressID,it has high priority.
-  // !!! Note: If the Pref is not the known Token used in the core but have same
+  // !!! Note: If the Perf is not the known Token used in the core but have same
   // ID with the core Token, this case will not be supported.
   // And in currtnt usage mode, for the unkown ID, there is a general rule:
   // If it is start pref: the lower 4 bits of the ID should be 0.
   // If it is end pref: the lower 4 bits of the ID should not be 0.
   // If input ID doesn't follow the rule, we will adjust it.
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [patch] MdeModulePkg/PerfLib: Add NULL pointer check for "Token"
Posted by Gao, Liming 6 years, 2 months ago
Reviewed-by: Liming Gao <liming.gao@intel.com>

>-----Original Message-----
>From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
>Dandan Bi
>Sent: Friday, February 09, 2018 4:04 PM
>To: edk2-devel@lists.01.org
>Cc: Yao, Jiewen <jiewen.yao@intel.com>; Zeng, Star <star.zeng@intel.com>;
>Gao, Liming <liming.gao@intel.com>
>Subject: [edk2] [patch] MdeModulePkg/PerfLib: Add NULL pointer check for
>"Token"
>
>"Token" is passed through the perf entry, it's may be NULL.
>So we need to add NULL pointer check before reference it.
>
>Cc: Liming Gao <liming.gao@intel.com>
>Cc: Star Zeng <star.zeng@intel.com>
>Cc: Jiewen Yao <jiewen.yao@intel.com>
>Contributed-under: TianoCore Contribution Agreement 1.1
>Signed-off-by: Dandan Bi <dandan.bi@intel.com>
>---
> MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
>| 6 +++++-
> MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c         | 6
>+++++-
>
>MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.
>c | 6 +++++-
> 3 files changed, 15 insertions(+), 3 deletions(-)
>
>diff --git
>a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.
>c
>b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.
>c
>index 8363b0e..9b3224e 100644
>---
>a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.
>c
>+++
>b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.
>c
>@@ -113,10 +113,14 @@ Check whether the Token is a known one which is
>uesed by core.
> BOOLEAN
> IsKnownTokens (
>   IN CONST CHAR8  *Token
>   )
> {
>+  if (Token == NULL) {
>+    return FALSE;
>+  }
>+
>   if (AsciiStrCmp (Token, SEC_TOK) == 0 ||
>       AsciiStrCmp (Token, PEI_TOK) == 0 ||
>       AsciiStrCmp (Token, DXE_TOK) == 0 ||
>       AsciiStrCmp (Token, BDS_TOK) == 0 ||
>       AsciiStrCmp (Token, DRIVERBINDING_START_TOK) == 0 ||
>@@ -845,11 +849,11 @@ InsertFpdtMeasurement (
>     return Status;
>   }
>
>   //
>   // If PERF_START()/PERF_END() have specified the ProgressID,it has high
>priority.
>-  // !!! Note: If the Pref is not the known Token used in the core but have
>same
>+  // !!! Note: If the Perf is not the known Token used in the core but have
>same
>   // ID with the core Token, this case will not be supported.
>   // And in currtnt usage mode, for the unkown ID, there is a general rule:
>   // If it is start pref: the lower 4 bits of the ID should be 0.
>   // If it is end pref: the lower 4 bits of the ID should not be 0.
>   // If input ID doesn't follow the rule, we will adjust it.
>diff --git a/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c
>b/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c
>index 79b67e8..f770a35 100644
>--- a/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c
>+++ b/MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c
>@@ -47,10 +47,14 @@ Check whether the Token is a known one which is
>uesed by core.
> BOOLEAN
> IsKnownTokens (
>   IN CONST CHAR8  *Token
>   )
> {
>+  if (Token == NULL) {
>+    return FALSE;
>+  }
>+
>   if (AsciiStrCmp (Token, SEC_TOK) == 0 ||
>       AsciiStrCmp (Token, PEI_TOK) == 0 ||
>       AsciiStrCmp (Token, DXE_TOK) == 0 ||
>       AsciiStrCmp (Token, BDS_TOK) == 0 ||
>       AsciiStrCmp (Token, DRIVERBINDING_START_TOK) == 0 ||
>@@ -264,11 +268,11 @@ InsertPeiFpdtMeasurement (
>     return Status;
>   }
>
>   //
>   // If PERF_START()/PERF_END() have specified the ProgressID,it has high
>priority.
>-  // !!! Note: If the Pref is not the known Token used in the core but have
>same
>+  // !!! Note: If the Perf is not the known Token used in the core but have
>same
>   // ID with the core Token, this case will not be supported.
>   // And in currtnt usage mode, for the unkown ID, there is a general rule:
>   // If it is start pref: the lower 4 bits of the ID should be 0.
>   // If it is end pref: the lower 4 bits of the ID should not be 0.
>   // If input ID doesn't follow the rule, we will adjust it.
>diff --git
>a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceL
>ib.c
>b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceL
>ib.c
>index 2834a68..dbc1166 100644
>---
>a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceL
>ib.c
>+++
>b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceL
>ib.c
>@@ -83,10 +83,14 @@ Check whether the Token is a known one which is
>uesed by core.
> BOOLEAN
> IsKnownTokens (
>   IN CONST CHAR8  *Token
>   )
> {
>+  if (Token == NULL) {
>+    return FALSE;
>+  }
>+
>   if (AsciiStrCmp (Token, SEC_TOK) == 0 ||
>       AsciiStrCmp (Token, PEI_TOK) == 0 ||
>       AsciiStrCmp (Token, DXE_TOK) == 0 ||
>       AsciiStrCmp (Token, BDS_TOK) == 0 ||
>       AsciiStrCmp (Token, DRIVERBINDING_START_TOK) == 0 ||
>@@ -495,11 +499,11 @@ InsertFpdtMeasurement (
>     return Status;
>   }
>
>   //
>   // If PERF_START()/PERF_END() have specified the ProgressID,it has high
>priority.
>-  // !!! Note: If the Pref is not the known Token used in the core but have
>same
>+  // !!! Note: If the Perf is not the known Token used in the core but have
>same
>   // ID with the core Token, this case will not be supported.
>   // And in currtnt usage mode, for the unkown ID, there is a general rule:
>   // If it is start pref: the lower 4 bits of the ID should be 0.
>   // If it is end pref: the lower 4 bits of the ID should not be 0.
>   // If input ID doesn't follow the rule, we will adjust it.
>--
>1.9.5.msysgit.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