Skip to content

Commit

Permalink
ocvalidate: Add AsciiGuidIsLegal API
Browse files Browse the repository at this point in the history
  • Loading branch information
PMheart committed Dec 27, 2020
1 parent 380ea0c commit 3869e19
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
13 changes: 13 additions & 0 deletions Utilities/ocvalidate/OcValidateLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,19 @@ AsciiDevicePathIsLegal (
return RetVal;
}

BOOLEAN
AsciiGuidIsLegal (
IN CONST CHAR8 *AsciiGuid
)
{
EFI_STATUS Status;
GUID Guid;

Status = AsciiStrToGuid (AsciiGuid, &Guid);

return !EFI_ERROR (Status);
}

BOOLEAN
DataHasProperMasking (
IN CONST VOID *Data,
Expand Down
12 changes: 12 additions & 0 deletions Utilities/ocvalidate/OcValidateLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ AsciiDevicePathIsLegal (
IN CONST CHAR8 *AsciiDevicePath
);

/**
Check if a GUID in ASCII is valid.
@param[in] AsciiGuid GUID to be checked.
@retval TRUE If AsciiGuid has valid GUID format.
**/
BOOLEAN
AsciiGuidIsLegal (
IN CONST CHAR8 *AsciiGuid
);

/**
Check if a set of data has proper masking set.
Expand Down
11 changes: 3 additions & 8 deletions Utilities/ocvalidate/ValidateNVRAM.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ CheckNVRAM (
)
{
UINT32 ErrorCount;
EFI_STATUS Status;
UINT32 GuidIndex;
UINT32 VariableIndex;
OC_NVRAM_CONFIG *UserNVRAM;
CONST CHAR8 *AsciiGuid;
CONST CHAR8 *AsciiNVRAMKey;
GUID VariableGuid;
OC_ASSOC *VariableMap;

DEBUG ((DEBUG_VERBOSE, "config loaded into NVRAM checker!\n"));
Expand All @@ -38,9 +36,8 @@ CheckNVRAM (

for (GuidIndex = 0; GuidIndex < UserNVRAM->Add.Count; ++GuidIndex) {
AsciiGuid = OC_BLOB_GET (UserNVRAM->Add.Keys[GuidIndex]);
Status = AsciiStrToGuid (AsciiGuid, &VariableGuid);

if (EFI_ERROR (Status)) {
if (!AsciiGuidIsLegal (AsciiGuid)) {
DEBUG ((DEBUG_WARN, "NVRAM->Add[%u] has borked GUID!\n", GuidIndex));
++ErrorCount;
}
Expand All @@ -67,9 +64,8 @@ CheckNVRAM (

for (GuidIndex = 0; GuidIndex < UserNVRAM->Delete.Count; ++GuidIndex) {
AsciiGuid = OC_BLOB_GET (UserNVRAM->Delete.Keys[GuidIndex]);
Status = AsciiStrToGuid (AsciiGuid, &VariableGuid);

if (EFI_ERROR (Status)) {
if (!AsciiGuidIsLegal (AsciiGuid)) {
DEBUG ((DEBUG_WARN, "NVRAM->Delete[%u] has borked GUID!\n", GuidIndex));
++ErrorCount;
}
Expand All @@ -94,9 +90,8 @@ CheckNVRAM (

for (GuidIndex = 0; GuidIndex < UserNVRAM->Legacy.Count; ++GuidIndex) {
AsciiGuid = OC_BLOB_GET (UserNVRAM->Legacy.Keys[GuidIndex]);
Status = AsciiStrToGuid (AsciiGuid, &VariableGuid);

if (EFI_ERROR (Status)) {
if (!AsciiGuidIsLegal (AsciiGuid)) {
DEBUG ((DEBUG_WARN, "NVRAM->LegacySchema[%u] has borked GUID!\n", GuidIndex));
++ErrorCount;
}
Expand Down
5 changes: 1 addition & 4 deletions Utilities/ocvalidate/ValidatePlatformInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ CheckPlatformInfo (
)
{
UINT32 ErrorCount;
EFI_STATUS Status;
OC_PLATFORM_CONFIG *UserPlatformInfo;
BOOLEAN IsAutomaticEnabled;
CONST CHAR8 *UpdateSMBIOSMode;
CONST CHAR8 *SystemProductName;
CONST CHAR8 *SystemMemoryStatus;
CONST CHAR8 *AsciiSystemUUID;
GUID Guid;

DEBUG ((DEBUG_VERBOSE, "config loaded into PlatformInfo checker!\n"));

Expand Down Expand Up @@ -73,8 +71,7 @@ CheckPlatformInfo (
++ErrorCount;
}

Status = AsciiStrToGuid (AsciiSystemUUID, &Guid);
if (EFI_ERROR (Status)) {
if (AsciiSystemUUID[0] != '\0' && !AsciiGuidIsLegal (AsciiSystemUUID)) {
DEBUG ((DEBUG_WARN, "PlatformInfo->Generic->SystemUUID is borked!\n"));
++ErrorCount;
}
Expand Down

0 comments on commit 3869e19

Please sign in to comment.