From 8d3000031dfc8b1d529e97d4471782bf636a84bf Mon Sep 17 00:00:00 2001 From: ydong10 Date: Thu, 26 Apr 2012 02:00:30 +0000 Subject: [PATCH] Enhance code to more safely and follow coding style. Signed-off-by: Eric Dong Reviewed-by: Jaben Carsey git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13221 6f19259b-4bc3-4df7-8a09-765794883524 --- .../UefiHandleParsingLib.c | 5 +++++ .../Library/UefiShellDebug1CommandsLib/Bcfg.c | 10 ++++++++-- .../UefiShellInstall1CommandsLib/Bcfg.c | 10 ++++++++-- .../UefiShellInstall1CommandsLib.uni | Bin 15646 -> 15858 bytes 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c index 6e44bcec75..400b24046c 100644 --- a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c +++ b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c @@ -203,12 +203,14 @@ PciRootBridgeIoDumpInformation( } Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_PH), NULL); + ASSERT (Temp != NULL); Temp2 = CatSPrint(L"\r\n", Temp, PciRootBridgeIo->ParentHandle); FreePool(Temp); RetVal = Temp2; Temp2 = NULL; Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_SEG), NULL); + ASSERT (Temp != NULL); Temp2 = CatSPrint(RetVal, Temp, PciRootBridgeIo->SegmentNumber); FreePool(Temp); FreePool(RetVal); @@ -220,6 +222,7 @@ PciRootBridgeIoDumpInformation( Status = PciRootBridgeIo->GetAttributes (PciRootBridgeIo, &Supports, &Attributes); if (!EFI_ERROR(Status)) { Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_ATT), NULL); + ASSERT (Temp != NULL); Temp2 = CatSPrint(RetVal, Temp, Attributes); FreePool(Temp); FreePool(RetVal); @@ -227,6 +230,7 @@ PciRootBridgeIoDumpInformation( Temp2 = NULL; Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_SUPPORTS), NULL); + ASSERT (Temp != NULL); Temp2 = CatSPrint(RetVal, Temp, Supports); FreePool(Temp); FreePool(RetVal); @@ -238,6 +242,7 @@ PciRootBridgeIoDumpInformation( Status = PciRootBridgeIo->Configuration (PciRootBridgeIo, (VOID **) &Configuration); if (!EFI_ERROR(Status) && Configuration != NULL) { Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_TITLE), NULL); + ASSERT (Temp != NULL); Temp2 = CatSPrint(RetVal, Temp, Supports); FreePool(Temp); FreePool(RetVal); diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c index 4d2fbfa843..fcf5b5014c 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c @@ -107,6 +107,7 @@ UpdateOptionalDataDebug1( // // Allocate new struct and discard old optional data. // + ASSERT (OriginalData != NULL); OriginalOptionDataSize = sizeof(UINT32) + sizeof(UINT16) + StrSize(((CHAR16*)(OriginalData + sizeof(UINT32) + sizeof(UINT16)))); OriginalOptionDataSize += (*(UINT16*)(OriginalData + sizeof(UINT32))); OriginalOptionDataSize -= OriginalSize; @@ -139,8 +140,8 @@ UpdateOptionalDataDebug1( /** This function will get a CRC for a boot option. - @param[in, out] Crc The CRC value to return. - @param[in] Index The boot option index to CRC. + @param[in, out] Crc The CRC value to return. + @param[in] BootIndex The boot option index to CRC. @retval EFI_SUCCESS The CRC was sucessfully returned. @retval other A error occured. @@ -779,6 +780,11 @@ BcfgAddOptDebug1( ShellStatus = SHELL_INVALID_PARAMETER; } else { FileName = StrnCatGrow(&FileName, NULL, Walker+1, 0); + if (FileName == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle); + ShellStatus = SHELL_OUT_OF_RESOURCES; + return (ShellStatus); + } Temp2 = StrStr(FileName, L"\""); ASSERT(Temp2 != NULL); Temp2[0] = CHAR_NULL; diff --git a/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c b/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c index e800533b6f..1f19712862 100644 --- a/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c +++ b/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c @@ -107,6 +107,7 @@ UpdateOptionalData( // // Allocate new struct and discard old optional data. // + ASSERT (OriginalData != NULL); OriginalOptionDataSize = sizeof(UINT32) + sizeof(UINT16) + StrSize(((CHAR16*)(OriginalData + sizeof(UINT32) + sizeof(UINT16)))); OriginalOptionDataSize += (*(UINT16*)(OriginalData + sizeof(UINT32))); OriginalOptionDataSize -= OriginalSize; @@ -139,8 +140,8 @@ UpdateOptionalData( /** This function will get a CRC for a boot option. - @param[in, out] Crc The CRC value to return. - @param[in] Index The boot option index to CRC. + @param[in, out] Crc The CRC value to return. + @param[in] BootIndex The boot option index to CRC. @retval EFI_SUCCESS The CRC was sucessfully returned. @retval other A error occured. @@ -779,6 +780,11 @@ BcfgAddOptInstall1( ShellStatus = SHELL_INVALID_PARAMETER; } else { FileName = StrnCatGrow(&FileName, NULL, Walker+1, 0); + if (FileName == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellInstall1HiiHandle); + ShellStatus = SHELL_OUT_OF_RESOURCES; + return (ShellStatus); + } Temp2 = StrStr(FileName, L"\""); ASSERT(Temp2 != NULL); Temp2[0] = CHAR_NULL; diff --git a/ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.uni b/ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.uni index 7c34ac502906d6d877d869f8288fa8aa5ba562b3..d4b030abb6f2bc64cc116905f8e2a588581351cf 100644 GIT binary patch delta 82 zcmbPN^{INp8=lDl+#J0A4517m4Dk%U46Y2mlNLm@LP}$DPQK1BCeu$qb2; h?^{X>7c-Os*~tv448=g02IS>TRunMa{EbJ$007nh7Ha?i delta 12 TcmexVJ+ErR8=lPvc#RAIE|~@p