REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2605
I think it is necessary that check the buffer size before ReadFile, it
will inform the caller that they should provide more buffer.
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Andrew Fish <afish@apple.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Guomin Jiang <guomin.jiang@intel.com>
---
EmulatorPkg/Win/Host/WinFileSystem.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/EmulatorPkg/Win/Host/WinFileSystem.c b/EmulatorPkg/Win/Host/WinFileSystem.c
index f6b06b1c92..6fb86db6b3 100644
--- a/EmulatorPkg/Win/Host/WinFileSystem.c
+++ b/EmulatorPkg/Win/Host/WinFileSystem.c
@@ -1159,6 +1159,12 @@ WinNtFileRead (
}
}
+ if (FileSize > *BufferSize) {
+ Status = EFI_BUFFER_TOO_SMALL;
+ *BufferSize = FileSize;
+ goto Done;
+ }
+
Status = ReadFile (
PrivateFile->LHandle,
Buffer,
--
2.25.1.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#56050): https://edk2.groups.io/g/devel/message/56050
Mute This Topic: https://groups.io/mt/72094663/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Guomin, It's OK to do a partial read. There is no requirement for a single read that returns all the file content back to caller. Some comments to your commit message: Besides, the commit message is too simple. It should indicate what was wrong in the code and what's your expected behavior. The Bugzilla comments are very detailed actually. Thanks, Ray > -----Original Message----- > From: Jiang, Guomin <guomin.jiang@intel.com> > Sent: Friday, March 20, 2020 2:56 PM > To: devel@edk2.groups.io > Cc: Justen, Jordan L <jordan.l.justen@intel.com>; Andrew Fish > <afish@apple.com>; Ni, Ray <ray.ni@intel.com> > Subject: [PATCH] EmulatorPkg/WinHost: Add EFI_BUFFER_TOO_SMALL for > return status. > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2605 > > I think it is necessary that check the buffer size before ReadFile, it > will inform the caller that they should provide more buffer. > > Cc: Jordan Justen <jordan.l.justen@intel.com> > Cc: Andrew Fish <afish@apple.com> > Cc: Ray Ni <ray.ni@intel.com> > Signed-off-by: Guomin Jiang <guomin.jiang@intel.com> > --- > EmulatorPkg/Win/Host/WinFileSystem.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/EmulatorPkg/Win/Host/WinFileSystem.c > b/EmulatorPkg/Win/Host/WinFileSystem.c > index f6b06b1c92..6fb86db6b3 100644 > --- a/EmulatorPkg/Win/Host/WinFileSystem.c > +++ b/EmulatorPkg/Win/Host/WinFileSystem.c > @@ -1159,6 +1159,12 @@ WinNtFileRead ( > } > > } > > > > + if (FileSize > *BufferSize) { > > + Status = EFI_BUFFER_TOO_SMALL; > > + *BufferSize = FileSize; > > + goto Done; > > + } > > + > > Status = ReadFile ( > > PrivateFile->LHandle, > > Buffer, > > -- > 2.25.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#56051): https://edk2.groups.io/g/devel/message/56051 Mute This Topic: https://groups.io/mt/72094663/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
Hi Ray, I have review the UEFI spec and code, the logic is ok, it my mistake. In my test, I pass the *BufferSize with 0, but it is unexpected input value. Sorry for it. > -----Original Message----- > From: Ni, Ray > Sent: Friday, March 20, 2020 3:12 PM > To: Jiang, Guomin <guomin.jiang@intel.com>; devel@edk2.groups.io > Cc: Justen, Jordan L <jordan.l.justen@intel.com>; Andrew Fish > <afish@apple.com> > Subject: RE: [PATCH] EmulatorPkg/WinHost: Add EFI_BUFFER_TOO_SMALL > for return status. > > Guomin, > It's OK to do a partial read. There is no requirement for a single read that > returns all the file content back to caller. > > Some comments to your commit message: > Besides, the commit message is too simple. It should indicate what was > wrong in the code and what's your expected behavior. > > The Bugzilla comments are very detailed actually. > > Thanks, > Ray > > > -----Original Message----- > > From: Jiang, Guomin <guomin.jiang@intel.com> > > Sent: Friday, March 20, 2020 2:56 PM > > To: devel@edk2.groups.io > > Cc: Justen, Jordan L <jordan.l.justen@intel.com>; Andrew Fish > > <afish@apple.com>; Ni, Ray <ray.ni@intel.com> > > Subject: [PATCH] EmulatorPkg/WinHost: Add EFI_BUFFER_TOO_SMALL for > > return status. > > > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2605 > > > > I think it is necessary that check the buffer size before ReadFile, it > > will inform the caller that they should provide more buffer. > > > > Cc: Jordan Justen <jordan.l.justen@intel.com> > > Cc: Andrew Fish <afish@apple.com> > > Cc: Ray Ni <ray.ni@intel.com> > > Signed-off-by: Guomin Jiang <guomin.jiang@intel.com> > > --- > > EmulatorPkg/Win/Host/WinFileSystem.c | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > > diff --git a/EmulatorPkg/Win/Host/WinFileSystem.c > > b/EmulatorPkg/Win/Host/WinFileSystem.c > > index f6b06b1c92..6fb86db6b3 100644 > > --- a/EmulatorPkg/Win/Host/WinFileSystem.c > > +++ b/EmulatorPkg/Win/Host/WinFileSystem.c > > @@ -1159,6 +1159,12 @@ WinNtFileRead ( > > } > > > > } > > > > > > > > + if (FileSize > *BufferSize) { > > > > + Status = EFI_BUFFER_TOO_SMALL; > > > > + *BufferSize = FileSize; > > > > + goto Done; > > > > + } > > > > + > > > > Status = ReadFile ( > > > > PrivateFile->LHandle, > > > > Buffer, > > > > -- > > 2.25.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#56081): https://edk2.groups.io/g/devel/message/56081 Mute This Topic: https://groups.io/mt/72094663/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2024 Red Hat, Inc.