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.jus...@intel.com>
Cc: Andrew Fish <af...@apple.com>
Cc: Ray Ni <ray...@intel.com>
Signed-off-by: Guomin Jiang <guomin.ji...@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/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to