Message ID | 20190913145100.303433-5-anthony.perard@citrix.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | OvmfPkg/XenBusDxe: Fix ExitBootServices handler to avoid allocation | expand |
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>
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
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(-)