Skip to content

Commit

Permalink
RedfishClientPkg/RedfishFeatureUtilityLib: add string NULL check
Browse files Browse the repository at this point in the history
Add string NULL check in attribute comparison function and prevent
NULL string assertion. This is not supposed to happen in normal
condition so add error output for debugging purpose.

Signed-off-by: Nickle Wang <[email protected]>
Cc: Abner Chang <[email protected]>
Cc: Igor Kulchytskyy <[email protected]>
Cc: Nick Ramirez <[email protected]>
  • Loading branch information
nicklela committed Nov 23, 2023
1 parent b68fd7d commit 7fdad96
Showing 1 changed file with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3743,6 +3743,15 @@ CompareRedfishPropertyVagueValues (
// Loop through all key/value on Redfish service..
//
while (ThisRedfishVagueKeyValuePtr != NULL) {
//
// Empty attribute string check.
//
if (IS_EMPTY_STRING (ThisConfigVagueKeyValuePtr->KeyNamePtr) || IS_EMPTY_STRING (ThisRedfishVagueKeyValuePtr->KeyNamePtr)) {
DEBUG ((DEBUG_ERROR, "%a: empty attribute name detected!!\n", __func__));
ThisRedfishVagueKeyValuePtr = ThisRedfishVagueKeyValuePtr->NextKeyValuePtr;
continue;
}

if (AsciiStrCmp (ThisConfigVagueKeyValuePtr->KeyNamePtr, ThisRedfishVagueKeyValuePtr->KeyNamePtr) == 0) {
//
// Check the type of value.
Expand All @@ -3758,28 +3767,36 @@ CompareRedfishPropertyVagueValues (
//
// Is the string identical?
//
if (AsciiStrCmp (
ThisConfigVagueKeyValuePtr->Value->DataValue.CharPtr,
ThisRedfishVagueKeyValuePtr->Value->DataValue.CharPtr
) == 0)
{
break;
if ((ThisConfigVagueKeyValuePtr->Value->DataValue.CharPtr != NULL) && (ThisRedfishVagueKeyValuePtr->Value->DataValue.CharPtr != NULL)) {
if (AsciiStrCmp (
ThisConfigVagueKeyValuePtr->Value->DataValue.CharPtr,
ThisRedfishVagueKeyValuePtr->Value->DataValue.CharPtr
) == 0)
{
break;
} else {
DEBUG ((REDFISH_DEBUG_TRACE, "%a: %a is updated\n", __func__, ThisConfigVagueKeyValuePtr->KeyNamePtr));
return FALSE;
}
} else {
return FALSE;
DEBUG ((DEBUG_ERROR, "%a: NULL attribute (%a) value detected!!\n", __func__, ThisConfigVagueKeyValuePtr->KeyNamePtr));
}
} else if (ThisConfigVagueKeyValuePtr->Value->DataType == RedfishCS_Vague_DataType_Int64) {
if (*ThisConfigVagueKeyValuePtr->Value->DataValue.Int64Ptr == *ThisRedfishVagueKeyValuePtr->Value->DataValue.Int64Ptr) {
break;
} else {
DEBUG ((REDFISH_DEBUG_TRACE, "%a: %a is updated\n", __func__, ThisConfigVagueKeyValuePtr->KeyNamePtr));
return FALSE;
}
} else if (ThisConfigVagueKeyValuePtr->Value->DataType == RedfishCS_Vague_DataType_Bool) {
if ((UINT8)*ThisConfigVagueKeyValuePtr->Value->DataValue.BoolPtr == (UINT8)*ThisRedfishVagueKeyValuePtr->Value->DataValue.BoolPtr) {
break;
} else {
DEBUG ((REDFISH_DEBUG_TRACE, "%a: %a is updated\n", __func__, ThisConfigVagueKeyValuePtr->KeyNamePtr));
return FALSE;
}
} else {
DEBUG ((REDFISH_DEBUG_TRACE, "%a: %a unsupported type: 0x%x\n", __func__, ThisConfigVagueKeyValuePtr->KeyNamePtr, ThisConfigVagueKeyValuePtr->Value->DataType));
return FALSE;
}
}
Expand Down

0 comments on commit 7fdad96

Please sign in to comment.