]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Security/OpalHii.c: Handle NULL Request or Request with no elements
authorDandan Bi <dandan.bi@intel.com>
Mon, 16 Oct 2017 03:37:08 +0000 (11:37 +0800)
committerEric Dong <eric.dong@intel.com>
Tue, 17 Oct 2017 05:23:06 +0000 (13:23 +0800)
According to UEFI spec, for the ExtractConfig function in
EFI_HII_CONFIG_ACCESS_PROTOCOL,If a NULL is passed in for the Request
field or if a ConfigHdr is passed in with no request elements, all of
the settings being abstracted by this function will be returned in the
Results field.

The implementation of ExtractConfig function in OpalHii.c misses to
handle above cases.This patch is to do the enhancements.

Cc: Chao Zhang <chao.b.zhang@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
SecurityPkg/Tcg/Opal/OpalPasswordDxe/OpalHii.c

index 4881e72c557ffb8282e6b12718a7f4156da9942a..e3bde4275dfa73a9be861fb41fe6e5e653b7a7d5 100644 (file)
@@ -1280,6 +1280,12 @@ ExtractConfig(
   )\r
 {\r
   EFI_STATUS                              Status;\r
+  EFI_STRING                              ConfigRequest;\r
+  EFI_STRING                              ConfigRequestHdr;\r
+  UINTN                                   BufferSize;\r
+  UINTN                                   Size;\r
+  BOOLEAN                                 AllocatedRequest;\r
+  EFI_HANDLE                              DriverHandle;\r
 \r
   //\r
   // Check for valid parameters\r
@@ -1294,18 +1300,56 @@ ExtractConfig(
     return EFI_NOT_FOUND;\r
   }\r
 \r
+  AllocatedRequest = FALSE;\r
+  BufferSize = sizeof (OPAL_HII_CONFIGURATION);\r
+  ConfigRequest = Request;\r
+  if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {\r
+    //\r
+    // Request has no request element, construct full request string.\r
+    // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
+    // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r
+    //\r
+    DriverHandle = HiiGetDriverImageHandleCB();\r
+    ConfigRequestHdr = HiiConstructConfigHdr (&gHiiSetupVariableGuid, OpalPasswordStorageName, DriverHandle);\r
+    Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
+    ConfigRequest = AllocateZeroPool (Size);\r
+    if (ConfigRequest == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    AllocatedRequest = TRUE;\r
+    UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);\r
+    FreePool (ConfigRequestHdr);\r
+  }\r
+\r
   //\r
   // Convert Buffer Data to <ConfigResp> by helper function BlockToConfig( )\r
   //\r
   Status = gHiiConfigRouting->BlockToConfig(\r
                gHiiConfigRouting,\r
-               Request,\r
+               ConfigRequest,\r
                (UINT8*)&gHiiConfiguration,\r
                sizeof(OPAL_HII_CONFIGURATION),\r
                Results,\r
                Progress\r
            );\r
 \r
+  //\r
+  // Free the allocated config request string.\r
+  //\r
+  if (AllocatedRequest) {\r
+    FreePool (ConfigRequest);\r
+    ConfigRequest = NULL;\r
+  }\r
+\r
+  //\r
+  // Set Progress string to the original request string.\r
+  //\r
+  if (Request == NULL) {\r
+    *Progress = NULL;\r
+  } else if (StrStr (Request, L"OFFSET") == NULL) {\r
+    *Progress = Request + StrLen (Request);\r
+  }\r
+\r
   return (Status);\r
 }\r
 \r