[04/11] OvmfPkg/XenBusDxe: Avoid Allocate in XenStoreVSPrint
diff mbox series

Message ID 20190913145100.303433-5-anthony.perard@citrix.com
State New
Headers show
Series
  • OvmfPkg/XenBusDxe: Fix ExitBootServices handler to avoid allocation
Related show

Commit Message

Anthony PERARD Sept. 13, 2019, 2:50 p.m. UTC
In order to be able to use XenStoreVSPrint during the
ExitBootServices, we remove the allocation done by the function and
use the stack instead.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2190
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 OvmfPkg/XenBusDxe/XenStore.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

Comments

Laszlo Ersek Sept. 16, 2019, 2:45 p.m. UTC | #1
On 09/13/19 16:50, Anthony PERARD wrote:
> In order to be able to use XenStoreVSPrint during the
> ExitBootServices, we remove the allocation done by the function and
> use the stack instead.
> 
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2190
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> ---
>  OvmfPkg/XenBusDxe/XenStore.c | 21 +++++++++------------
>  1 file changed, 9 insertions(+), 12 deletions(-)
> 
> diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c
> index 5cc900190a..7b71dc156d 100644
> --- a/OvmfPkg/XenBusDxe/XenStore.c
> +++ b/OvmfPkg/XenBusDxe/XenStore.c
> @@ -1259,20 +1259,17 @@ XenStoreVSPrint (
>    IN VA_LIST               Marker
>    )
>  {
> -  CHAR8 *Buf;
> -  XENSTORE_STATUS Status;
> -  UINTN BufSize;
> -  VA_LIST Marker2;
> +  CHAR8           Buf[XENSTORE_PAYLOAD_MAX];
> +  UINTN           Count;
>  
> -  VA_COPY (Marker2, Marker);
> -  BufSize = SPrintLengthAsciiFormat (FormatString, Marker2) + 1;
> -  VA_END (Marker2);
> -  Buf = AllocateZeroPool (BufSize);
> -  AsciiVSPrint (Buf, BufSize, FormatString, Marker);
> -  Status = XenStoreWrite (Transaction, DirectoryPath, Node, Buf);
> -  FreePool (Buf);
> +  Count = AsciiVSPrint (Buf, sizeof (Buf), FormatString, Marker);
> +  ASSERT (Count > 0);
> +  ASSERT (Count < sizeof (Buf));
> +  if ((Count == 0) || (Count >= sizeof (Buf))) {
> +    return XENSTORE_STATUS_EINVAL;
> +  }
>  
> -  return Status;
> +  return XenStoreWrite (Transaction, DirectoryPath, Node, Buf);
>  }
>  
>  XENSTORE_STATUS
> 

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Patch
diff mbox series

diff --git a/OvmfPkg/XenBusDxe/XenStore.c b/OvmfPkg/XenBusDxe/XenStore.c
index 5cc900190a..7b71dc156d 100644
--- a/OvmfPkg/XenBusDxe/XenStore.c
+++ b/OvmfPkg/XenBusDxe/XenStore.c
@@ -1259,20 +1259,17 @@  XenStoreVSPrint (
   IN VA_LIST               Marker
   )
 {
-  CHAR8 *Buf;
-  XENSTORE_STATUS Status;
-  UINTN BufSize;
-  VA_LIST Marker2;
+  CHAR8           Buf[XENSTORE_PAYLOAD_MAX];
+  UINTN           Count;
 
-  VA_COPY (Marker2, Marker);
-  BufSize = SPrintLengthAsciiFormat (FormatString, Marker2) + 1;
-  VA_END (Marker2);
-  Buf = AllocateZeroPool (BufSize);
-  AsciiVSPrint (Buf, BufSize, FormatString, Marker);
-  Status = XenStoreWrite (Transaction, DirectoryPath, Node, Buf);
-  FreePool (Buf);
+  Count = AsciiVSPrint (Buf, sizeof (Buf), FormatString, Marker);
+  ASSERT (Count > 0);
+  ASSERT (Count < sizeof (Buf));
+  if ((Count == 0) || (Count >= sizeof (Buf))) {
+    return XENSTORE_STATUS_EINVAL;
+  }
 
-  return Status;
+  return XenStoreWrite (Transaction, DirectoryPath, Node, Buf);
 }
 
 XENSTORE_STATUS