Reviewed-by: Fu Siyuan <siyuan...@intel.com> > -----Original Message----- > From: Wu, Jiaxin > Sent: Wednesday, June 15, 2016 4:26 PM > To: edk2-devel@lists.01.org > Cc: Fu, Siyuan <siyuan...@intel.com>; Ye, Ting <ting...@intel.com>; Zeng, > Star <star.z...@intel.com> > 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 <siyuan...@intel.com> > Cc: Ye Ting <ting...@intel.com> > Cc: Zeng Star <star.z...@intel.com> > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Jiaxin Wu <jiaxin...@intel.com> > --- > 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.<BR> > + Copyright (c) 2009 - 2016, 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 > 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.<BR> > + Copyright (c) 2009 - 2016, 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 > 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; > + UINT8 Name[MAX_PEERID_LEN]; > UINTN Index; // Used only if Name is NULL. > } SPD_ENTRY_INDEXER; > > typedef struct { > EFI_IPSEC_SA_ID SaId; > 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.<BR> > + Copyright (c) 2009 - 2016, 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 > which accompanies this distribution. The full text of the license may be > found at > http://opensource.org/licenses/bsd-license.php. > @@ -61,11 +61,11 @@ MatchSpdEntry ( > ) > { > BOOLEAN Match; > > Match = FALSE; > - if (Indexer->Name != NULL) { > + if (!IsMemoryZero (Indexer->Name, MAX_PEERID_LEN)) { > if ((Data->Name != NULL) && (AsciiStrCmp ((CHAR8 *) Indexer->Name, > (CHAR8 *) Data->Name) == 0)) { > Match = TRUE; > } > } else { > if (Indexer->Index == 0) { > -- > 1.9.5.msysgit.1
_______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel