This patch introduces addtional parameter passed to
InternalGetSectionFromFv function that acted as a flag showed
that *Buffer is a valid pointer to caller allocated buffer.

Currently InternalGetSectionFromFv does not allow to pass caller allocated 
buffer
down to EFI_FIRMWARE_VOLUME2_PROTOCOL. It is assumed that data will be
returned within buffer allocated by callee.

Meanwhile EfiSectionExtractionProtocol producer is able to store
section data to buffer allocated by caller.
It does a partial read of a section and return EFI_WARN_BUFFER_TOO_SMALL
as operation status if provided buffer too small for extraced section.
Thus caller able to detect partial read condition.

Prevention of a pre allocated buffers does not allow to caller
overlap sections or use continuous buffers for concatenation.

Contributed-under: TianoCore Contribution Agreement 1.0

Signed-off-by: Mike Maslenkin <[email protected]>
---
 MdePkg/Library/DxeServicesLib/DxeServicesLib.c |   42 ++++++++++++++++++------
 1 file changed, 32 insertions(+), 10 deletions(-)

diff --git a/MdePkg/Library/DxeServicesLib/DxeServicesLib.c 
b/MdePkg/Library/DxeServicesLib/DxeServicesLib.c
index ef7c9ba..308b952 100644
--- a/MdePkg/Library/DxeServicesLib/DxeServicesLib.c
+++ b/MdePkg/Library/DxeServicesLib/DxeServicesLib.c
@@ -94,9 +94,16 @@ InternalImageHandleToFvHandle (
   @param  SectionType             The Firmware Section type.
   @param  SectionInstance         The instance number of Firmware Section to  
                                   read from starting from 0.
-  @param  Buffer                  On output, Buffer contains the the data read 
-                                  from the section in the Firmware File found.
-  @param  Size                    On output, the size of Buffer.
+  @param  Allocate                A flag that requires a memory allocation 
made by callee
+  @param  Buffer                  Double indirection to buffer.
+                                  On input if Allocate is TRUE then the buffer
+                                  is callee allocated and must be a valid 
pointer to
+                                  caller allocated buffer otherwise.
+                                  On output, Buffer contains the the data read
+                                   from the section in the Firmware File found.
+  @param  Size                    On input, indicates the size of *Buffer
+                                  On output, indicates the required
+                                  size (allocated size if callee allocated) of 
*Buffer.
 
   @retval  EFI_SUCCESS            The image is found and data and size is 
returned.
   @retval  EFI_NOT_FOUND          The image specified by NameGuid and 
SectionType 
@@ -107,7 +114,10 @@ InternalImageHandleToFvHandle (
                                   Firmware Volume.
   @retval  EFI_ACCESS_DENIED      The firmware volume containing the searched 
                                   Firmware File is configured to disallow 
reads.
-  
+  @retval  EFI_WARN_TOO_SMALL     The size of the caller allocated input 
buffer is
+                                  insufficient to contain the requested 
section.
+                                  The input buffer is filled and contents are 
section
+                                  contents are truncated.
 **/
 EFI_STATUS
 InternalGetSectionFromFv (
@@ -115,8 +125,9 @@ InternalGetSectionFromFv (
   IN  CONST EFI_GUID                *NameGuid,
   IN  EFI_SECTION_TYPE              SectionType,
   IN  UINTN                         SectionInstance,
-  OUT VOID                          **Buffer,
-  OUT UINTN                         *Size
+  IN  BOOLEAN                       Allocate,
+  IN OUT VOID                       **Buffer,
+  IN OUT UINTN                      *Size
   )
 {
   EFI_STATUS                    Status;
@@ -141,8 +152,11 @@ InternalGetSectionFromFv (
   //
   // Read desired section content in NameGuid file
   //
-  *Buffer     = NULL;
-  *Size       = 0;
+  if (Allocate) {
+    *Buffer     = NULL;
+    *Size       = 0;
+  }
+
   Status      = Fv->ReadSection (
                       Fv,
                       NameGuid,
@@ -157,8 +171,11 @@ InternalGetSectionFromFv (
     //
     // Try reading PE32 section, if the required section is TE type 
     //
-    *Buffer = NULL;
-    *Size   = 0;
+    if (Allocate) {
+      *Buffer = NULL;
+      *Size   = 0;
+    }
+
     Status  = Fv->ReadSection (
                     Fv,
                     NameGuid,
@@ -293,6 +310,7 @@ GetSectionFromAnyFvByFileType  (
                  &NameGuid,
                  SectionType,
                  SectionInstance,
+                 TRUE,
                  Buffer,
                  Size
                  );
@@ -389,6 +407,7 @@ GetSectionFromAnyFv  (
              NameGuid,
              SectionType,
              SectionInstance,
+             TRUE,
              Buffer,
              Size
              );
@@ -418,6 +437,7 @@ GetSectionFromAnyFv  (
                  NameGuid, 
                  SectionType, 
                  SectionInstance,
+                 TRUE,
                  Buffer, 
                  Size
                  );
@@ -502,6 +522,7 @@ GetSectionFromFv (
            NameGuid,
            SectionType,
            SectionInstance,
+           TRUE,
            Buffer,
            Size
            );
@@ -564,6 +585,7 @@ GetSectionFromFfs (
            &gEfiCallerIdGuid,
            SectionType,
            SectionInstance,
+           TRUE,
            Buffer,
            Size
            );
-- 
1.7.10.4


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to