[edk2] [Patch] NetworkPkg: Fix unspecified address use case in IpsecConfig

2016-06-15 Thread Jiaxin Wu
This patch is used to fix unspecified address use case in
ConstructSpdIndexer() function. Indexer->Name for
ConstructSpdIndexer is unspecified, that will be a problem
for UnicodeStrToAsciiStr.

This patch also refine the code by removing ASSERT and user
error handling.

Cc: Fu Siyuan 
Cc: Ye Ting 
Cc: Zeng Star 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu 
---
 NetworkPkg/Application/IpsecConfig/Indexer.c | 26 --
 NetworkPkg/Application/IpsecConfig/Indexer.h |  4 ++--
 NetworkPkg/Application/IpsecConfig/Match.c   |  4 ++--
 3 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/NetworkPkg/Application/IpsecConfig/Indexer.c 
b/NetworkPkg/Application/IpsecConfig/Indexer.c
index 83ceda4..353b22e 100644
--- a/NetworkPkg/Application/IpsecConfig/Indexer.c
+++ b/NetworkPkg/Application/IpsecConfig/Indexer.c
@@ -1,9 +1,9 @@
 /** @file
   The implementation of construct ENTRY_INDEXER in IpSecConfig application.
 
-  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
+  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
   http://opensource.org/licenses/bsd-license.php.
@@ -42,21 +42,23 @@ ConstructSpdIndexer (
   } else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
   } else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
   } else {
-ASSERT (FALSE);
+return EFI_INVALID_PARAMETER;
   }
 
-  ASSERT (ValueStr != NULL);
-
+  if (ValueStr == NULL) {
+return EFI_INVALID_PARAMETER;
+  }
+  
   Value64 = StrToUInteger (ValueStr, &Status);
   if (!EFI_ERROR (Status)) {
 Indexer->Index = (UINTN) Value64;
-Indexer->Name  = NULL;
+ZeroMem (Indexer->Name, MAX_PEERID_LEN);
   } else {
-UnicodeStrToAsciiStr (ValueStr, (CHAR8 *) Indexer->Name);
+UnicodeStrToAsciiStrS (ValueStr, (CHAR8 *) Indexer->Name, MAX_PEERID_LEN);
   }
 
   return EFI_SUCCESS;
 }
 
@@ -87,14 +89,16 @@ ConstructSadIndexer (
   } else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
   } else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
   } else {
-ASSERT (FALSE);
+return EFI_INVALID_PARAMETER;
   }
 
-  ASSERT (ValueStr != NULL);
+  if (ValueStr == NULL) {
+return EFI_INVALID_PARAMETER;
+  }
 
   Value64 = StrToUInteger (ValueStr, &Status);
   if (!EFI_ERROR (Status)) {
 Indexer->Index = (UINTN) Value64;
 ZeroMem (&Indexer->SaId, sizeof (EFI_IPSEC_SA_ID));
@@ -185,14 +189,16 @@ ConstructPadIndexer (
   } else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
   } else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
   } else {
-ASSERT (FALSE);
+return EFI_INVALID_PARAMETER;
   }
 
-  ASSERT (ValueStr != NULL);
+  if (ValueStr == NULL) {
+return EFI_INVALID_PARAMETER;
+  }
 
   Value64 = StrToUInteger (ValueStr, &Status);
 
   if (!EFI_ERROR (Status)) {
 Indexer->Index = (UINTN) Value64;
diff --git a/NetworkPkg/Application/IpsecConfig/Indexer.h 
b/NetworkPkg/Application/IpsecConfig/Indexer.h
index 078f38a..b0e62fb 100644
--- a/NetworkPkg/Application/IpsecConfig/Indexer.h
+++ b/NetworkPkg/Application/IpsecConfig/Indexer.h
@@ -1,10 +1,10 @@
 /** @file
   The internal structure and function declaration to construct ENTRY_INDEXER in
   IpSecConfig application.
 
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
   http://opensource.org/licenses/bsd-license.php.
@@ -16,11 +16,11 @@
 
 #ifndef _INDEXER_H_
 #define _INDEXER_H_
 
 typedef struct {
-  UINT8*Name;
+  UINT8Name[MAX_PEERID_LEN];
   UINTNIndex;// Used only if Name is NULL.
 } SPD_ENTRY_INDEXER;
 
 typedef struct {
   EFI_IPSEC_SA_IDSaId;
diff --git a/NetworkPkg/Application/IpsecConfig/Match.c 
b/NetworkPkg/Application/IpsecConfig/Match.c
index d283f5b..2ee763e 100644
--- a/NetworkPkg/Application/IpsecConfig/Match.c
+++ b/NetworkPkg/Application/IpsecConfig/Match.c
@@ -1,9 +1,9 @@
 /** @file
   The implementation of match policy entry function in IpSecConfig application.
 
-  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
+  Copyright (c) 2009 - 2016, Intel Corporation. 

Re: [edk2] [Patch] NetworkPkg: Fix unspecified address use case in IpsecConfig

2016-06-15 Thread Zeng, Star
Please also update the comments below in SPD_ENTRY_INDEXER structure.

UINTNIndex;// Used only if Name is NULL.

With the comments updated, you can have my Reviewed-by: Star Zeng 


Thanks,
Star
-Original Message-
From: Wu, Jiaxin 
Sent: Wednesday, June 15, 2016 4:26 PM
To: edk2-devel@lists.01.org
Cc: Fu, Siyuan ; Ye, Ting ; Zeng, Star 

Subject: [Patch] NetworkPkg: Fix unspecified address use case in IpsecConfig

This patch is used to fix unspecified address use case in
ConstructSpdIndexer() function. Indexer->Name for ConstructSpdIndexer is 
unspecified, that will be a problem for UnicodeStrToAsciiStr.

This patch also refine the code by removing ASSERT and user error handling.

Cc: Fu Siyuan 
Cc: Ye Ting 
Cc: Zeng Star 
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu 
---
 NetworkPkg/Application/IpsecConfig/Indexer.c | 26 --  
NetworkPkg/Application/IpsecConfig/Indexer.h |  4 ++--
 NetworkPkg/Application/IpsecConfig/Match.c   |  4 ++--
 3 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/NetworkPkg/Application/IpsecConfig/Indexer.c 
b/NetworkPkg/Application/IpsecConfig/Indexer.c
index 83ceda4..353b22e 100644
--- a/NetworkPkg/Application/IpsecConfig/Indexer.c
+++ b/NetworkPkg/Application/IpsecConfig/Indexer.c
@@ -1,9 +1,9 @@
 /** @file
   The implementation of construct ENTRY_INDEXER in IpSecConfig application.
 
-  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
+  Copyright (c) 2009 - 2016, Intel Corporation. All rights 
+ reserved.
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
   http://opensource.org/licenses/bsd-license.php.
@@ -42,21 +42,23 @@ ConstructSpdIndexer (
   } else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
   } else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
   } else {
-ASSERT (FALSE);
+return EFI_INVALID_PARAMETER;
   }
 
-  ASSERT (ValueStr != NULL);
-
+  if (ValueStr == NULL) {
+return EFI_INVALID_PARAMETER;
+  }
+  
   Value64 = StrToUInteger (ValueStr, &Status);
   if (!EFI_ERROR (Status)) {
 Indexer->Index = (UINTN) Value64;
-Indexer->Name  = NULL;
+ZeroMem (Indexer->Name, MAX_PEERID_LEN);
   } else {
-UnicodeStrToAsciiStr (ValueStr, (CHAR8 *) Indexer->Name);
+UnicodeStrToAsciiStrS (ValueStr, (CHAR8 *) Indexer->Name, 
+ MAX_PEERID_LEN);
   }
 
   return EFI_SUCCESS;
 }
 
@@ -87,14 +89,16 @@ ConstructSadIndexer (
   } else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
   } else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
   } else {
-ASSERT (FALSE);
+return EFI_INVALID_PARAMETER;
   }
 
-  ASSERT (ValueStr != NULL);
+  if (ValueStr == NULL) {
+return EFI_INVALID_PARAMETER;
+  }
 
   Value64 = StrToUInteger (ValueStr, &Status);
   if (!EFI_ERROR (Status)) {
 Indexer->Index = (UINTN) Value64;
 ZeroMem (&Indexer->SaId, sizeof (EFI_IPSEC_SA_ID)); @@ -185,14 +189,16 @@ 
ConstructPadIndexer (
   } else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
   } else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
 ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
   } else {
-ASSERT (FALSE);
+return EFI_INVALID_PARAMETER;
   }
 
-  ASSERT (ValueStr != NULL);
+  if (ValueStr == NULL) {
+return EFI_INVALID_PARAMETER;
+  }
 
   Value64 = StrToUInteger (ValueStr, &Status);
 
   if (!EFI_ERROR (Status)) {
 Indexer->Index = (UINTN) Value64;
diff --git a/NetworkPkg/Application/IpsecConfig/Indexer.h 
b/NetworkPkg/Application/IpsecConfig/Indexer.h
index 078f38a..b0e62fb 100644
--- a/NetworkPkg/Application/IpsecConfig/Indexer.h
+++ b/NetworkPkg/Application/IpsecConfig/Indexer.h
@@ -1,10 +1,10 @@
 /** @file
   The internal structure and function declaration to construct ENTRY_INDEXER in
   IpSecConfig application.
 
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+  Copyright (c) 2009 - 2016, Intel Corporation. All rights 
+ reserved.
 
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
   http://opensource.org/licenses/bsd-license.php.
@@ -16,11 +16,11 @@
 
 #ifndef _INDEXER_H_
 #define _INDEXER_H_
 
 typedef struct {
-  UINT8*Name;
+  UINT8Name[MAX_PEERID_LEN];
   UINTNIndex;// Used only if Name is NULL.
 } SPD_ENTRY_INDEXER;
 
 typedef struct {
   EFI_IPSEC_SA_IDSaId;
diff --git a/

Re: [edk2] [Patch] NetworkPkg: Fix unspecified address use case in IpsecConfig

2016-06-15 Thread Wu, Jiaxin
Thanks for catching.  I will update it before commit.  /Jiaxin.

> -Original Message-
> From: Zeng, Star
> Sent: Wednesday, June 15, 2016 4:32 PM
> To: Wu, Jiaxin ; edk2-devel@lists.01.org
> Cc: Fu, Siyuan ; Ye, Ting ; Zeng,
> Star 
> Subject: RE: [Patch] NetworkPkg: Fix unspecified address use case in
> IpsecConfig
> 
> Please also update the comments below in SPD_ENTRY_INDEXER structure.
> 
> UINTNIndex;// Used only if Name is NULL.
> 
> With the comments updated, you can have my Reviewed-by: Star Zeng
> 
> 
> Thanks,
> Star
> -Original Message-
> From: Wu, Jiaxin
> Sent: Wednesday, June 15, 2016 4:26 PM
> To: edk2-devel@lists.01.org
> Cc: Fu, Siyuan ; Ye, Ting ; Zeng,
> Star 
> Subject: [Patch] NetworkPkg: Fix unspecified address use case in IpsecConfig
> 
> This patch is used to fix unspecified address use case in
> ConstructSpdIndexer() function. Indexer->Name for ConstructSpdIndexer is
> unspecified, that will be a problem for UnicodeStrToAsciiStr.
> 
> This patch also refine the code by removing ASSERT and user error handling.
> 
> Cc: Fu Siyuan 
> Cc: Ye Ting 
> Cc: Zeng Star 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jiaxin Wu 
> ---
>  NetworkPkg/Application/IpsecConfig/Indexer.c | 26 ---
> ---  NetworkPkg/Application/IpsecConfig/Indexer.h |  4 ++--
>  NetworkPkg/Application/IpsecConfig/Match.c   |  4 ++--
>  3 files changed, 20 insertions(+), 14 deletions(-)
> 
> diff --git a/NetworkPkg/Application/IpsecConfig/Indexer.c
> b/NetworkPkg/Application/IpsecConfig/Indexer.c
> index 83ceda4..353b22e 100644
> --- a/NetworkPkg/Application/IpsecConfig/Indexer.c
> +++ b/NetworkPkg/Application/IpsecConfig/Indexer.c
> @@ -1,9 +1,9 @@
>  /** @file
>The implementation of construct ENTRY_INDEXER in IpSecConfig application.
> 
> -  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
> +  Copyright (c) 2009 - 2016, Intel Corporation. All rights
> + reserved.
> 
>This program and the accompanying materials
>are licensed and made available under the terms and conditions of the BSD
> License
>which accompanies this distribution.  The full text of the license may be
> found at
>http://opensource.org/licenses/bsd-license.php.
> @@ -42,21 +42,23 @@ ConstructSpdIndexer (
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
>} else {
> -ASSERT (FALSE);
> +return EFI_INVALID_PARAMETER;
>}
> 
> -  ASSERT (ValueStr != NULL);
> -
> +  if (ValueStr == NULL) {
> +return EFI_INVALID_PARAMETER;
> +  }
> +
>Value64 = StrToUInteger (ValueStr, &Status);
>if (!EFI_ERROR (Status)) {
>  Indexer->Index = (UINTN) Value64;
> -Indexer->Name  = NULL;
> +ZeroMem (Indexer->Name, MAX_PEERID_LEN);
>} else {
> -UnicodeStrToAsciiStr (ValueStr, (CHAR8 *) Indexer->Name);
> +UnicodeStrToAsciiStrS (ValueStr, (CHAR8 *) Indexer->Name,
> + MAX_PEERID_LEN);
>}
> 
>return EFI_SUCCESS;
>  }
> 
> @@ -87,14 +89,16 @@ ConstructSadIndexer (
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
>} else {
> -ASSERT (FALSE);
> +return EFI_INVALID_PARAMETER;
>}
> 
> -  ASSERT (ValueStr != NULL);
> +  if (ValueStr == NULL) {
> +return EFI_INVALID_PARAMETER;
> +  }
> 
>Value64 = StrToUInteger (ValueStr, &Status);
>if (!EFI_ERROR (Status)) {
>  Indexer->Index = (UINTN) Value64;
>  ZeroMem (&Indexer->SaId, sizeof (EFI_IPSEC_SA_ID)); @@ -185,14
> +189,16 @@ ConstructPadIndexer (
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
>} else {
> -ASSERT (FALSE);
> +return EFI_INVALID_PARAMETER;
>}
> 
> -  ASSERT (ValueStr != NULL);
> +  if (ValueStr == NULL) {
> +return EFI_INVALID_PARAMETER;
> +  }
> 
>Value64 = StrToUInteger (ValueStr, &Status);
> 
>if (!EFI_ERROR (Status)) {
>  Indexer->Index = (UINTN) Value64;
> diff --git a/NetworkPkg/Application/IpsecConfig/Indexer.h
> b/NetworkPkg/Application/IpsecConfig/Indexer.h
> index 078f38a..b0e62fb 100644
> --- a/NetworkPkg/Application/IpsecConfig/Indexer.h
> +++ b/NetworkPkg/Application/IpsecConfig/Indexer.h
> @@ -1,10 +1,10 @@
>  /** @file
>The internal structure and function declaration to construct
> ENTRY_INDEXER in
>IpSecConfig application.
> 
> -  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
> +  Copyright (c) 2009 - 2016, Intel Corporati

Re: [edk2] [Patch] NetworkPkg: Fix unspecified address use case in IpsecConfig

2016-06-16 Thread Ye, Ting
Reviewed-by: Ye Ting  

-Original Message-
From: Wu, Jiaxin 
Sent: Wednesday, June 15, 2016 4:34 PM
To: Zeng, Star ; edk2-devel@lists.01.org
Cc: Fu, Siyuan ; Ye, Ting 
Subject: RE: [Patch] NetworkPkg: Fix unspecified address use case in IpsecConfig

Thanks for catching.  I will update it before commit.  /Jiaxin.

> -Original Message-
> From: Zeng, Star
> Sent: Wednesday, June 15, 2016 4:32 PM
> To: Wu, Jiaxin ; edk2-devel@lists.01.org
> Cc: Fu, Siyuan ; Ye, Ting ; 
> Zeng, Star 
> Subject: RE: [Patch] NetworkPkg: Fix unspecified address use case in 
> IpsecConfig
> 
> Please also update the comments below in SPD_ENTRY_INDEXER structure.
> 
> UINTNIndex;// Used only if Name is NULL.
> 
> With the comments updated, you can have my Reviewed-by: Star Zeng 
> 
> 
> Thanks,
> Star
> -Original Message-
> From: Wu, Jiaxin
> Sent: Wednesday, June 15, 2016 4:26 PM
> To: edk2-devel@lists.01.org
> Cc: Fu, Siyuan ; Ye, Ting ; 
> Zeng, Star 
> Subject: [Patch] NetworkPkg: Fix unspecified address use case in 
> IpsecConfig
> 
> This patch is used to fix unspecified address use case in
> ConstructSpdIndexer() function. Indexer->Name for ConstructSpdIndexer 
> is unspecified, that will be a problem for UnicodeStrToAsciiStr.
> 
> This patch also refine the code by removing ASSERT and user error handling.
> 
> Cc: Fu Siyuan 
> Cc: Ye Ting 
> Cc: Zeng Star 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jiaxin Wu 
> ---
>  NetworkPkg/Application/IpsecConfig/Indexer.c | 26 ---
> ---  NetworkPkg/Application/IpsecConfig/Indexer.h |  4 ++--
>  NetworkPkg/Application/IpsecConfig/Match.c   |  4 ++--
>  3 files changed, 20 insertions(+), 14 deletions(-)
> 
> diff --git a/NetworkPkg/Application/IpsecConfig/Indexer.c
> b/NetworkPkg/Application/IpsecConfig/Indexer.c
> index 83ceda4..353b22e 100644
> --- a/NetworkPkg/Application/IpsecConfig/Indexer.c
> +++ b/NetworkPkg/Application/IpsecConfig/Indexer.c
> @@ -1,9 +1,9 @@
>  /** @file
>The implementation of construct ENTRY_INDEXER in IpSecConfig application.
> 
> -  Copyright (c) 2009 - 2015, Intel Corporation. All rights 
> reserved.
> +  Copyright (c) 2009 - 2016, Intel Corporation. All rights 
> + reserved.
> 
>This program and the accompanying materials
>are licensed and made available under the terms and conditions of 
> the BSD License
>which accompanies this distribution.  The full text of the license 
> may be found at
>http://opensource.org/licenses/bsd-license.php.
> @@ -42,21 +42,23 @@ ConstructSpdIndexer (
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
>} else {
> -ASSERT (FALSE);
> +return EFI_INVALID_PARAMETER;
>}
> 
> -  ASSERT (ValueStr != NULL);
> -
> +  if (ValueStr == NULL) {
> +return EFI_INVALID_PARAMETER;
> +  }
> +
>Value64 = StrToUInteger (ValueStr, &Status);
>if (!EFI_ERROR (Status)) {
>  Indexer->Index = (UINTN) Value64;
> -Indexer->Name  = NULL;
> +ZeroMem (Indexer->Name, MAX_PEERID_LEN);
>} else {
> -UnicodeStrToAsciiStr (ValueStr, (CHAR8 *) Indexer->Name);
> +UnicodeStrToAsciiStrS (ValueStr, (CHAR8 *) Indexer->Name, 
> + MAX_PEERID_LEN);
>}
> 
>return EFI_SUCCESS;
>  }
> 
> @@ -87,14 +89,16 @@ ConstructSadIndexer (
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
>} else {
> -ASSERT (FALSE);
> +return EFI_INVALID_PARAMETER;
>}
> 
> -  ASSERT (ValueStr != NULL);
> +  if (ValueStr == NULL) {
> +return EFI_INVALID_PARAMETER;
> +  }
> 
>Value64 = StrToUInteger (ValueStr, &Status);
>if (!EFI_ERROR (Status)) {
>  Indexer->Index = (UINTN) Value64;
>  ZeroMem (&Indexer->SaId, sizeof (EFI_IPSEC_SA_ID)); @@ -185,14
> +189,16 @@ ConstructPadIndexer (
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
>} else {
> -ASSERT (FALSE);
> +return EFI_INVALID_PARAMETER;
>}
> 
> -  ASSERT (ValueStr != NULL);
> +  if (ValueStr == NULL) {
> +return EFI_INVALID_PARAMETER;
> +  }
> 
>Value64 = StrToUInteger (ValueStr, &Status);
> 
>if (!EFI_ERROR (Status)) {
>  Indexer->Index = (UINTN) Value64; diff --git 
> a/NetworkPkg/Application/IpsecConfig/Indexer.h
> b/NetworkPkg/Application/IpsecConfig/Indexer.h
> index 078f38a..b0e62fb 100644
> --- a/NetworkPkg/Application/IpsecConfig/Indexer.h
> +++ b/NetworkPkg/Application/IpsecConfig/Indexe

Re: [edk2] [Patch] NetworkPkg: Fix unspecified address use case in IpsecConfig

2016-06-16 Thread Fu, Siyuan
Reviewed-by: Fu Siyuan 

> -Original Message-
> From: Wu, Jiaxin
> Sent: Wednesday, June 15, 2016 4:26 PM
> To: edk2-devel@lists.01.org
> Cc: Fu, Siyuan ; Ye, Ting ; Zeng,
> Star 
> Subject: [Patch] NetworkPkg: Fix unspecified address use case in IpsecConfig
> 
> This patch is used to fix unspecified address use case in
> ConstructSpdIndexer() function. Indexer->Name for
> ConstructSpdIndexer is unspecified, that will be a problem
> for UnicodeStrToAsciiStr.
> 
> This patch also refine the code by removing ASSERT and user
> error handling.
> 
> Cc: Fu Siyuan 
> Cc: Ye Ting 
> Cc: Zeng Star 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jiaxin Wu 
> ---
>  NetworkPkg/Application/IpsecConfig/Indexer.c | 26 ---
> ---
>  NetworkPkg/Application/IpsecConfig/Indexer.h |  4 ++--
>  NetworkPkg/Application/IpsecConfig/Match.c   |  4 ++--
>  3 files changed, 20 insertions(+), 14 deletions(-)
> 
> diff --git a/NetworkPkg/Application/IpsecConfig/Indexer.c
> b/NetworkPkg/Application/IpsecConfig/Indexer.c
> index 83ceda4..353b22e 100644
> --- a/NetworkPkg/Application/IpsecConfig/Indexer.c
> +++ b/NetworkPkg/Application/IpsecConfig/Indexer.c
> @@ -1,9 +1,9 @@
>  /** @file
>The implementation of construct ENTRY_INDEXER in IpSecConfig
> application.
> 
> -  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
> +  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
> 
>This program and the accompanying materials
>are licensed and made available under the terms and conditions of the BSD
> License
>which accompanies this distribution.  The full text of the license may be
> found at
>http://opensource.org/licenses/bsd-license.php.
> @@ -42,21 +42,23 @@ ConstructSpdIndexer (
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
>} else {
> -ASSERT (FALSE);
> +return EFI_INVALID_PARAMETER;
>}
> 
> -  ASSERT (ValueStr != NULL);
> -
> +  if (ValueStr == NULL) {
> +return EFI_INVALID_PARAMETER;
> +  }
> +
>Value64 = StrToUInteger (ValueStr, &Status);
>if (!EFI_ERROR (Status)) {
>  Indexer->Index = (UINTN) Value64;
> -Indexer->Name  = NULL;
> +ZeroMem (Indexer->Name, MAX_PEERID_LEN);
>} else {
> -UnicodeStrToAsciiStr (ValueStr, (CHAR8 *) Indexer->Name);
> +UnicodeStrToAsciiStrS (ValueStr, (CHAR8 *) Indexer->Name,
> MAX_PEERID_LEN);
>}
> 
>return EFI_SUCCESS;
>  }
> 
> @@ -87,14 +89,16 @@ ConstructSadIndexer (
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
>} else {
> -ASSERT (FALSE);
> +return EFI_INVALID_PARAMETER;
>}
> 
> -  ASSERT (ValueStr != NULL);
> +  if (ValueStr == NULL) {
> +return EFI_INVALID_PARAMETER;
> +  }
> 
>Value64 = StrToUInteger (ValueStr, &Status);
>if (!EFI_ERROR (Status)) {
>  Indexer->Index = (UINTN) Value64;
>  ZeroMem (&Indexer->SaId, sizeof (EFI_IPSEC_SA_ID));
> @@ -185,14 +189,16 @@ ConstructPadIndexer (
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d");
>} else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) {
>  ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e");
>} else {
> -ASSERT (FALSE);
> +return EFI_INVALID_PARAMETER;
>}
> 
> -  ASSERT (ValueStr != NULL);
> +  if (ValueStr == NULL) {
> +return EFI_INVALID_PARAMETER;
> +  }
> 
>Value64 = StrToUInteger (ValueStr, &Status);
> 
>if (!EFI_ERROR (Status)) {
>  Indexer->Index = (UINTN) Value64;
> diff --git a/NetworkPkg/Application/IpsecConfig/Indexer.h
> b/NetworkPkg/Application/IpsecConfig/Indexer.h
> index 078f38a..b0e62fb 100644
> --- a/NetworkPkg/Application/IpsecConfig/Indexer.h
> +++ b/NetworkPkg/Application/IpsecConfig/Indexer.h
> @@ -1,10 +1,10 @@
>  /** @file
>The internal structure and function declaration to construct
> ENTRY_INDEXER in
>IpSecConfig application.
> 
> -  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
> +  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
> 
>This program and the accompanying materials
>are licensed and made available under the terms and conditions of the BSD
> License
>which accompanies this distribution.  The full text of the license may be
> found at
>http://opensource.org/licenses/bsd-license.php.
> @@ -16,11 +16,11 @@
> 
>  #ifndef _INDEXER_H_
>  #define _INDEXER_H_
> 
>  typedef struct {
> -  UINT8*Name;
> +  UINT8Name[MAX_PEERID_LEN];
>UINTNIndex;// Used only if Name is NULL.
>  } SPD