From 6c6967d4a6073313fe7b53b881eaba6014c7f72b Mon Sep 17 00:00:00 2001 From: Qiu Shumin Date: Thu, 10 Sep 2015 05:24:32 +0000 Subject: MdePkg: Refine UefiFileHandleLib to avoid write non-ASCII char into ASCII file. (Sync patch r18430 from main trunk.) Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Qiu Shumin Reviewed-by: Liming Gao Reviewed-by: Jaben Carsey git-svn-id: https://svn.code.sf.net/p/edk2/code/branches/UDK2015@18432 6f19259b-4bc3-4df7-8a09-765794883524 --- MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c index 04a2f189ec..dfec5fa4d4 100644 --- a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c +++ b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c @@ -1079,6 +1079,7 @@ FileHandleWriteLine( EFI_STATUS Status; CHAR16 CharBuffer; UINTN Size; + UINTN Index; UINTN CharSize; UINT64 FileSize; UINT64 OriginalFilePosition; @@ -1136,6 +1137,12 @@ FileHandleWriteLine( return EFI_OUT_OF_RESOURCES; } UnicodeStrToAsciiStr (Buffer, AsciiBuffer); + for (Index = 0; Index < Size; Index++) { + if (!((AsciiBuffer[Index] >= 0) && (AsciiBuffer[Index] < 128))){ + FreePool(AsciiBuffer); + return EFI_INVALID_PARAMETER; + } + } Size = AsciiStrSize(AsciiBuffer) - sizeof(CHAR8); Status = FileHandleWrite(Handle, &Size, AsciiBuffer); -- cgit v1.2.3