]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c
According to UEFI spec 2.3.1a. hardware error record variable should use the EFI_HARD...
[mirror_edk2.git] / SecurityPkg / VariableAuthenticated / RuntimeDxe / Variable.c
index d3e0b7766e8d96d065dba767abcc52eeececd1cd..49358de0138cafe3f33a39a8cf9f822e09709710 100644 (file)
@@ -1884,6 +1884,63 @@ Done:
   return Status;\r
 }\r
 \r
+/**\r
+  Check if a Unicode character is a hexadecimal character.\r
+\r
+  This function checks if a Unicode character is a \r
+  hexadecimal character.  The valid hexadecimal character is \r
+  L'0' to L'9', L'a' to L'f', or L'A' to L'F'.\r
+\r
+\r
+  @param Char           The character to check against.\r
+\r
+  @retval TRUE          If the Char is a hexadecmial character.\r
+  @retval FALSE         If the Char is not a hexadecmial character.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsHexaDecimalDigitCharacter (\r
+  IN CHAR16             Char\r
+  )\r
+{\r
+  return (BOOLEAN) ((Char >= L'0' && Char <= L'9') || (Char >= L'A' && Char <= L'F') || (Char >= L'a' && Char <= L'f'));\r
+}\r
+\r
+/**\r
+\r
+  This code checks if variable is hardware error record variable or not.\r
+\r
+  According to UEFI spec, hardware error record variable should use the EFI_HARDWARE_ERROR_VARIABLE VendorGuid\r
+  and have the L"HwErrRec####" name convention, #### is a printed hex value and no 0x or h is included in the hex value.\r
+\r
+  @param VariableName   Pointer to variable name.\r
+  @param VendorGuid     Variable Vendor Guid.\r
+\r
+  @retval TRUE          Variable is hardware error record variable.\r
+  @retval FALSE         Variable is not hardware error record variable.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsHwErrRecVariable (\r
+  IN CHAR16             *VariableName,\r
+  IN EFI_GUID           *VendorGuid\r
+  )\r
+{\r
+  if (!CompareGuid (VendorGuid, &gEfiHardwareErrorVariableGuid) ||\r
+      (StrLen (VariableName) != StrLen (L"HwErrRec####")) ||\r
+      (StrnCmp(VariableName, L"HwErrRec", StrLen (L"HwErrRec")) != 0) ||\r
+      !IsHexaDecimalDigitCharacter (VariableName[0x8]) ||\r
+      !IsHexaDecimalDigitCharacter (VariableName[0x9]) ||\r
+      !IsHexaDecimalDigitCharacter (VariableName[0xA]) ||\r
+      !IsHexaDecimalDigitCharacter (VariableName[0xB])) {\r
+    return FALSE;\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
 /**\r
 \r
   This code finds variable in storage blocks (Volatile or Non-Volatile).\r
@@ -2199,10 +2256,7 @@ VariableServiceSetVariable (
         (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + PayloadSize > PcdGet32 (PcdMaxHardwareErrorVariableSize))) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
-    //\r
-    // According to UEFI spec, HARDWARE_ERROR_RECORD variable name convention should be L"HwErrRecXXXX".\r
-    //\r
-    if (StrnCmp(VariableName, L"HwErrRec", StrLen(L"HwErrRec")) != 0) {\r
+    if (!IsHwErrRecVariable(VariableName, VendorGuid)) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
   } else {\r