Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedfishPkg/RedfishPlatformConfigDxe: check attribute max. and min. value #6452

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1764,13 +1764,15 @@ RedfishPlatformConfigSetStatementCommon (
UINTN Index;
UINT64 Value;
CHAR8 **CharArray;
UINTN StrLength;

if ((RedfishPlatformConfigPrivate == NULL) || IS_EMPTY_STRING (Schema) || IS_EMPTY_STRING (ConfigureLang) || (StatementValue == NULL)) {
return EFI_INVALID_PARAMETER;
}

TempBuffer = NULL;
StringArray = NULL;
StrLength = 0;

Status = ProcessPendingList (&RedfishPlatformConfigPrivate->FormsetList, &RedfishPlatformConfigPrivate->PendingList);
if (EFI_ERROR (Status)) {
Expand Down Expand Up @@ -1840,19 +1842,44 @@ RedfishPlatformConfigSetStatementCommon (
StatementValue->Buffer = StringArray;
StatementValue->BufferLen = TargetStatement->HiiStatement->StorageWidth;
StatementValue->BufferValueType = TargetStatement->HiiStatement->Value.BufferValueType;
} else if ((TargetStatement->HiiStatement->Operand == EFI_IFR_NUMERIC_OP) && (StatementValue->Type == EFI_IFR_TYPE_NUM_SIZE_64)) {
} else if (TargetStatement->HiiStatement->Operand == EFI_IFR_NUMERIC_OP) {
if (StatementValue->Type == EFI_IFR_TYPE_NUM_SIZE_64) {
//
// Redfish only has numeric value type and it does not care about the value size.
// Do a patch here so we have proper value size applied.
//
StatementValue->Type = TargetStatement->HiiStatement->Value.Type;
}

//
// Redfish only has numeric value type and it does not care about the value size.
// Do a patch here so we have proper value size applied.
// Check maximum and minimum values.
//
StatementValue->Type = TargetStatement->HiiStatement->Value.Type;
if (StatementValue->Value.u64 > TargetStatement->StatementData.NumMaximum) {
DEBUG ((DEBUG_ERROR, "%a: integer value: %lu is greater than maximum value: %lu\n", __func__, StatementValue->Value.u64, TargetStatement->StatementData.NumMaximum));
return EFI_ACCESS_DENIED;
} else if (StatementValue->Value.u64 < TargetStatement->StatementData.NumMinimum) {
DEBUG ((DEBUG_ERROR, "%a: integer value: %lu is smaller than minimum value: %lu\n", __func__, StatementValue->Value.u64, TargetStatement->StatementData.NumMinimum));
return EFI_ACCESS_DENIED;
}
} else {
DEBUG ((DEBUG_ERROR, "%a: catch value type mismatch! input type: 0x%x but target value type: 0x%x\n", __func__, StatementValue->Type, TargetStatement->HiiStatement->Value.Type));
ASSERT (FALSE);
}
}

if ((TargetStatement->HiiStatement->Operand == EFI_IFR_STRING_OP) && (StatementValue->Type == EFI_IFR_TYPE_STRING)) {
//
// Check string length.
//
StrLength = StrLen ((EFI_STRING)StatementValue->Buffer);
if (StrLength > TargetStatement->StatementData.StrMaxSize) {
DEBUG ((DEBUG_ERROR, "%a: string length: %u is greater than maximum string length: %u\n", __func__, StrLength, TargetStatement->StatementData.StrMaxSize));
return EFI_ACCESS_DENIED;
} else if (StrLength < TargetStatement->StatementData.StrMinSize) {
DEBUG ((DEBUG_ERROR, "%a: string length: %u is smaller than minimum string length: %u\n", __func__, StrLength, TargetStatement->StatementData.StrMinSize));
return EFI_ACCESS_DENIED;
}

//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nickle,
what if some statement does not have StrMaxSize set?
Will we have it as 0 and the condition fail?
Or in this case the condition should not be verified?

// Create string ID for new string.
//
Expand Down
Loading