Add pointer check for NULL before dereference it.

Signed-off-by: ydong10
Reviewed-by: rsun3, lgao4

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12472 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
ydong10 2011-09-29 06:33:23 +00:00
parent 57ad9d43b1
commit 04eb20aa85
7 changed files with 28 additions and 5 deletions

View File

@ -341,6 +341,7 @@ FindStringBlock (
for (Index = 0; Index < StringCount; Index++) { for (Index = 0; Index < StringCount; Index++) {
BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr); BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr);
if (CurrentStringId == StringId) { if (CurrentStringId == StringId) {
ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL);
*BlockType = *BlockHdr; *BlockType = *BlockHdr;
*StringBlockAddr = BlockHdr; *StringBlockAddr = BlockHdr;
*StringTextOffset = StringTextPtr - BlockHdr; *StringTextOffset = StringTextPtr - BlockHdr;
@ -363,6 +364,7 @@ FindStringBlock (
for (Index = 0; Index < StringCount; Index++) { for (Index = 0; Index < StringCount; Index++) {
BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr); BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr);
if (CurrentStringId == StringId) { if (CurrentStringId == StringId) {
ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL);
*BlockType = *BlockHdr; *BlockType = *BlockHdr;
*StringBlockAddr = BlockHdr; *StringBlockAddr = BlockHdr;
*StringTextOffset = StringTextPtr - BlockHdr; *StringTextOffset = StringTextPtr - BlockHdr;
@ -406,6 +408,7 @@ FindStringBlock (
GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize); GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);
BlockSize += StringSize; BlockSize += StringSize;
if (CurrentStringId == StringId) { if (CurrentStringId == StringId) {
ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL);
*BlockType = *BlockHdr; *BlockType = *BlockHdr;
*StringBlockAddr = BlockHdr; *StringBlockAddr = BlockHdr;
*StringTextOffset = StringTextPtr - BlockHdr; *StringTextOffset = StringTextPtr - BlockHdr;
@ -429,6 +432,7 @@ FindStringBlock (
GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize); GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);
BlockSize += StringSize; BlockSize += StringSize;
if (CurrentStringId == StringId) { if (CurrentStringId == StringId) {
ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL);
*BlockType = *BlockHdr; *BlockType = *BlockHdr;
*StringBlockAddr = BlockHdr; *StringBlockAddr = BlockHdr;
*StringTextOffset = StringTextPtr - BlockHdr; *StringTextOffset = StringTextPtr - BlockHdr;
@ -572,7 +576,7 @@ FindStringBlock (
// //
// Get last string ID // Get last string ID
// //
if (StringId == (EFI_STRING_ID) (-1)) { if (StringId == (EFI_STRING_ID) (-1) && LastStringId != NULL) {
*LastStringId = (EFI_STRING_ID) (CurrentStringId - 1); *LastStringId = (EFI_STRING_ID) (CurrentStringId - 1);
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -533,6 +533,8 @@ ArpMatchAddress (
IN NET_ARP_ADDRESS *AddressTwo IN NET_ARP_ADDRESS *AddressTwo
) )
{ {
ASSERT (AddressOne != NULL && AddressTwo != NULL);
if ((AddressOne->Type != AddressTwo->Type) || if ((AddressOne->Type != AddressTwo->Type) ||
(AddressOne->Length != AddressTwo->Length)) { (AddressOne->Length != AddressTwo->Length)) {
// //

View File

@ -419,7 +419,15 @@ Ip4Reassemble (
} }
NewPacket->Ip.Ip4 = Assemble->Head; NewPacket->Ip.Ip4 = Assemble->Head;
CopyMem (IP4_GET_CLIP_INFO (NewPacket), Assemble->Info, sizeof (*IP4_GET_CLIP_INFO (NewPacket)));
ASSERT (Assemble->Info != NULL);
CopyMem (
IP4_GET_CLIP_INFO (NewPacket),
Assemble->Info,
sizeof (*IP4_GET_CLIP_INFO (NewPacket))
);
return NewPacket; return NewPacket;
} }
@ -1272,7 +1280,9 @@ Ip4InstanceDeliverPacket (
// headless. Trim the head off after copy. The IP head // headless. Trim the head off after copy. The IP head
// may be not continuous before the data. // may be not continuous before the data.
// //
Head = NetbufAllocSpace (Dup, IP4_MAX_HEADLEN, NET_BUF_HEAD); Head = NetbufAllocSpace (Dup, IP4_MAX_HEADLEN, NET_BUF_HEAD);
ASSERT (Head != NULL);
Dup->Ip.Ip4 = (IP4_HEAD *) Head; Dup->Ip.Ip4 = (IP4_HEAD *) Head;
CopyMem (Head, Packet->Ip.Ip4, Packet->Ip.Ip4->HeadLen << 2); CopyMem (Head, Packet->Ip.Ip4, Packet->Ip.Ip4->HeadLen << 2);

View File

@ -1122,6 +1122,7 @@ GetSelectionInputPopUp (
Link = GetNextNode (&Question->OptionListHead, Link); Link = GetNextNode (&Question->OptionListHead, Link);
StringPtr = GetToken (OneOfOption->Text, MenuOption->Handle); StringPtr = GetToken (OneOfOption->Text, MenuOption->Handle);
ASSERT (StringPtr != NULL);
// //
// If the string occupies multiple lines, truncate it to fit in one line, // If the string occupies multiple lines, truncate it to fit in one line,
// and append a "..." for indication. // and append a "..." for indication.

View File

@ -533,6 +533,7 @@ DisplayForm (
if (!Suppress) { if (!Suppress) {
StringPtr = GetToken (Statement->Prompt, Handle); StringPtr = GetToken (Statement->Prompt, Handle);
ASSERT (StringPtr != NULL);
Width = GetWidth (Statement, Handle); Width = GetWidth (Statement, Handle);

View File

@ -502,6 +502,7 @@ ProcessOptions (
Character[0] = LEFT_ONEOF_DELIMITER; Character[0] = LEFT_ONEOF_DELIMITER;
NewStrCat (OptionString[0], Character); NewStrCat (OptionString[0], Character);
StringPtr = GetToken (OneOfOption->Text, Selection->Handle); StringPtr = GetToken (OneOfOption->Text, Selection->Handle);
ASSERT (StringPtr != NULL);
NewStrCat (OptionString[0], StringPtr); NewStrCat (OptionString[0], StringPtr);
Character[0] = RIGHT_ONEOF_DELIMITER; Character[0] = RIGHT_ONEOF_DELIMITER;
NewStrCat (OptionString[0], Character); NewStrCat (OptionString[0], Character);
@ -599,6 +600,7 @@ ProcessOptions (
Character[0] = LEFT_ONEOF_DELIMITER; Character[0] = LEFT_ONEOF_DELIMITER;
NewStrCat (OptionString[0], Character); NewStrCat (OptionString[0], Character);
StringPtr = GetToken (OneOfOption->Text, Selection->Handle); StringPtr = GetToken (OneOfOption->Text, Selection->Handle);
ASSERT (StringPtr != NULL);
NewStrCat (OptionString[0], StringPtr); NewStrCat (OptionString[0], StringPtr);
Character[0] = RIGHT_ONEOF_DELIMITER; Character[0] = RIGHT_ONEOF_DELIMITER;
NewStrCat (OptionString[0], Character); NewStrCat (OptionString[0], Character);

View File

@ -1177,6 +1177,7 @@ EmuGetVariable (
VARIABLE_POINTER_TRACK Variable; VARIABLE_POINTER_TRACK Variable;
UINTN VarDataSize; UINTN VarDataSize;
EFI_STATUS Status; EFI_STATUS Status;
UINT8 *VariableDataPtr;
if (VariableName == NULL || VendorGuid == NULL || DataSize == NULL) { if (VariableName == NULL || VendorGuid == NULL || DataSize == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -1201,8 +1202,10 @@ EmuGetVariable (
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto Done; goto Done;
} }
VariableDataPtr = GetVariableDataPtr (Variable.CurrPtr);
CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize); ASSERT (VariableDataPtr != NULL);
CopyMem (Data, VariableDataPtr, VarDataSize);
if (Attributes != NULL) { if (Attributes != NULL) {
*Attributes = Variable.CurrPtr->Attributes; *Attributes = Variable.CurrPtr->Attributes;
} }