public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/2] Update comments and code for GetNextVariableName to follow UEFI 2.7
@ 2017-06-22 13:35 Star Zeng
  2017-06-22 13:35 ` [PATCH 1/2] MdePkg: Update comments " Star Zeng
  2017-06-22 13:35 ` [PATCH 2/2] MdeModulePkg Variable: Update " Star Zeng
  0 siblings, 2 replies; 3+ messages in thread
From: Star Zeng @ 2017-06-22 13:35 UTC (permalink / raw)
  To: edk2-devel; +Cc: Star Zeng

"The size must be large enough to fit input string supplied in
VariableName buffer" is added in the description for VariableNameSize.
And two cases of EFI_INVALID_PARAMETER are added.
1. The input values of VariableName and VendorGuid are not a name and
   GUID of an existing variable.
2. Null-terminator is not found in the first VariableNameSize bytes of
   the input VariableName buffer.

Star Zeng (2):
  MdePkg: Update comments for GetNextVariableName to follow UEFI 2.7
  MdeModulePkg Variable: Update GetNextVariableName to follow UEFI 2.7

 MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 19 +++++++++++++++++++
 MdePkg/Include/Uefi/UefiSpec.h                        |  7 ++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

-- 
2.7.0.windows.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] MdePkg: Update comments for GetNextVariableName to follow UEFI 2.7
  2017-06-22 13:35 [PATCH 0/2] Update comments and code for GetNextVariableName to follow UEFI 2.7 Star Zeng
@ 2017-06-22 13:35 ` Star Zeng
  2017-06-22 13:35 ` [PATCH 2/2] MdeModulePkg Variable: Update " Star Zeng
  1 sibling, 0 replies; 3+ messages in thread
From: Star Zeng @ 2017-06-22 13:35 UTC (permalink / raw)
  To: edk2-devel; +Cc: Star Zeng, Liming Gao

"The size must be large enough to fit input string supplied in
VariableName buffer" is added in the description for VariableNameSize.
And two cases of EFI_INVALID_PARAMETER are added.
1. The input values of VariableName and VendorGuid are not a name and
   GUID of an existing variable.
2. Null-terminator is not found in the first VariableNameSize bytes of
   the input VariableName buffer.

This patch is to update comments for GetNextVariableName to follow them.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
 MdePkg/Include/Uefi/UefiSpec.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Include/Uefi/UefiSpec.h b/MdePkg/Include/Uefi/UefiSpec.h
index eb662a35503c..0b84f4829749 100644
--- a/MdePkg/Include/Uefi/UefiSpec.h
+++ b/MdePkg/Include/Uefi/UefiSpec.h
@@ -661,7 +661,8 @@ EFI_STATUS
 /**
   Enumerates the current variable names.
 
-  @param[in, out]  VariableNameSize The size of the VariableName buffer.
+  @param[in, out]  VariableNameSize The size of the VariableName buffer. The size must be large
+                                    enough to fit input string supplied in VariableName buffer.
   @param[in, out]  VariableName     On input, supplies the last VariableName that was returned
                                     by GetNextVariableName(). On output, returns the Nullterminated
                                     string of the current variable.
@@ -675,6 +676,10 @@ EFI_STATUS
   @retval EFI_INVALID_PARAMETER VariableNameSize is NULL.
   @retval EFI_INVALID_PARAMETER VariableName is NULL.
   @retval EFI_INVALID_PARAMETER VendorGuid is NULL.
+  @retval EFI_INVALID_PARAMETER The input values of VariableName and VendorGuid are not a name and
+                                GUID of an existing variable.
+  @retval EFI_INVALID_PARAMETER Null-terminator is not found in the first VariableNameSize bytes of
+                                the input VariableName buffer.
   @retval EFI_DEVICE_ERROR      The variable could not be retrieved due to a hardware error.
 
 **/
-- 
2.7.0.windows.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] MdeModulePkg Variable: Update GetNextVariableName to follow UEFI 2.7
  2017-06-22 13:35 [PATCH 0/2] Update comments and code for GetNextVariableName to follow UEFI 2.7 Star Zeng
  2017-06-22 13:35 ` [PATCH 1/2] MdePkg: Update comments " Star Zeng
@ 2017-06-22 13:35 ` Star Zeng
  1 sibling, 0 replies; 3+ messages in thread
From: Star Zeng @ 2017-06-22 13:35 UTC (permalink / raw)
  To: edk2-devel; +Cc: Star Zeng, Liming Gao

"The size must be large enough to fit input string supplied in
VariableName buffer" is added in the description for VariableNameSize.
And two cases of EFI_INVALID_PARAMETER are added.
1. The input values of VariableName and VendorGuid are not a name and
   GUID of an existing variable.
2. Null-terminator is not found in the first VariableNameSize bytes of
   the input VariableName buffer.

This patch is to update code to follow them.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
---
 MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
index 0a325de1659d..d8f41d799238 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
@@ -2926,6 +2926,12 @@ VariableServiceGetNextVariableInternal (
 
   Status = FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
   if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {
+    if (VariableName[0] != 0) {
+      //
+      // The input values of VariableName and VendorGuid are not a name and GUID of an existing variable.
+      //
+      Status = EFI_INVALID_PARAMETER;
+    }
     goto Done;
   }
 
@@ -3065,6 +3071,7 @@ VariableServiceGetNextVariableName (
   )
 {
   EFI_STATUS              Status;
+  UINTN                   MaxLen;
   UINTN                   VarNameSize;
   VARIABLE_HEADER         *VariablePtr;
 
@@ -3072,6 +3079,18 @@ VariableServiceGetNextVariableName (
     return EFI_INVALID_PARAMETER;
   }
 
+  //
+  // Calculate the possible maximum length of name string, including the Null terminator.
+  //
+  MaxLen = *VariableNameSize / sizeof (CHAR16);
+  if ((MaxLen == 0) ||
+      ((VariableName[MaxLen - 1] != 0) && (StrnLenS (VariableName, MaxLen) >= MaxLen))) {
+    //
+    // Null-terminator is not found in the first VariableNameSize bytes of the input VariableName buffer.
+    //
+    return EFI_INVALID_PARAMETER;
+  }
+
   AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
 
   Status = VariableServiceGetNextVariableInternal (VariableName, VendorGuid, &VariablePtr);
-- 
2.7.0.windows.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-06-22 13:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-22 13:35 [PATCH 0/2] Update comments and code for GetNextVariableName to follow UEFI 2.7 Star Zeng
2017-06-22 13:35 ` [PATCH 1/2] MdePkg: Update comments " Star Zeng
2017-06-22 13:35 ` [PATCH 2/2] MdeModulePkg Variable: Update " Star Zeng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox