]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg/TlsAuthConfigDxe: fix TlsCaCertificate attributes retrieval
authorLaszlo Ersek <lersek@redhat.com>
Fri, 17 Aug 2018 13:12:38 +0000 (15:12 +0200)
committerLaszlo Ersek <lersek@redhat.com>
Wed, 22 Aug 2018 08:32:43 +0000 (10:32 +0200)
Per spec, the GetVariable() runtime service is not required to populate
(*Attributes) on output when it fails with EFI_BUFFER_TOO_SMALL.

Therefore we have to fetch the full contents of the TlsCaCertificate
variable temporarily, just so we can (a) get the current attributes, and
(b) add EFI_VARIABLE_APPEND_WRITE to them for the subsequent SetVariable()
call.

Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Cc: Songpeng Li <songpeng.li@intel.com>
Reported-by: Songpeng Li <songpeng.li@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1090
Fixes: b90c335fbbb674470fbf09601cc522bf61564c30
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Songpeng Li <songpeng.li@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c

index 7259c5e82f616fe1aefc3e92ac0b932b361f1823..0780b03bbab43f78fba3624d7da90915ec102112 100644 (file)
@@ -663,6 +663,7 @@ EnrollX509toVariable (
   EFI_SIGNATURE_LIST                *CACert;\r
   EFI_SIGNATURE_DATA                *CACertData;\r
   VOID                              *Data;\r
+  VOID                              *CurrentData;\r
   UINTN                             DataSize;\r
   UINTN                             SigDataSize;\r
   UINT32                            Attr;\r
@@ -674,6 +675,7 @@ EnrollX509toVariable (
   CACert        = NULL;\r
   CACertData    = NULL;\r
   Data          = NULL;\r
+  CurrentData   = NULL;\r
   Attr          = 0;\r
 \r
   Status = ReadFileContent (\r
@@ -716,11 +718,30 @@ EnrollX509toVariable (
   Status = gRT->GetVariable(\r
                   VariableName,\r
                   &gEfiTlsCaCertificateGuid,\r
-                  &Attr,\r
+                  NULL,\r
                   &DataSize,\r
                   NULL\r
                   );\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
+    //\r
+    // Per spec, we have to fetch the variable's contents, even though we're\r
+    // only interested in the variable's attributes.\r
+    //\r
+    CurrentData = AllocatePool (DataSize);\r
+    if (CurrentData == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto ON_EXIT;\r
+    }\r
+    Status = gRT->GetVariable(\r
+                    VariableName,\r
+                    &gEfiTlsCaCertificateGuid,\r
+                    &Attr,\r
+                    &DataSize,\r
+                    CurrentData\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      goto ON_EXIT;\r
+    }\r
     Attr |= EFI_VARIABLE_APPEND_WRITE;\r
   } else if (Status == EFI_NOT_FOUND) {\r
     Attr = TLS_AUTH_CONFIG_VAR_BASE_ATTR;\r
@@ -751,6 +772,10 @@ ON_EXIT:
     FreePool (Data);\r
   }\r
 \r
+  if (CurrentData != NULL) {\r
+    FreePool (CurrentData);\r
+  }\r
+\r
   if (X509Data != NULL) {\r
     FreePool (X509Data);\r
   }\r