From: Jiaxin Wu Date: Thu, 26 Apr 2018 06:13:57 +0000 (+0800) Subject: ShellPkg/TftpDynamicCommand: Fix the potential assertion and memory leak issue. X-Git-Tag: edk2-stable201903~1419 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=280f49b81170aee9176a47085b168ff3bc9fd3e7 ShellPkg/TftpDynamicCommand: Fix the potential assertion and memory leak issue. This patch is to fix the issue reported from https://bugzilla.tianocore.org/show_bug.cgi?id=925. DataSize variable was not assigned the value if ShellOpenFileByName returns error. In the such a case, it should not be used to FreePages. Instead, DataSize can be used to record the file size once DownloadFile successfully. Cc: Ye Ting Cc: Fu Siyuan Cc: Jaben Carsey Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Wu Jiaxin Reviewed-by: Fu Siyuan Reviewed-by: Jaben Carsey --- diff --git a/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c b/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c index e2491cd54c..44be6d4e76 100644 --- a/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c +++ b/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c @@ -519,6 +519,8 @@ RunTftp ( goto NextHandle; } + DataSize = FileSize; + if (!EFI_ERROR (ShellFileExists (LocalFilePath))) { ShellDeleteFileByName (LocalFilePath); } @@ -539,7 +541,6 @@ RunTftp ( goto NextHandle; } - DataSize = FileSize; Status = ShellWriteFile (FileHandle, &FileSize, Data); if (!EFI_ERROR (Status)) { ShellStatus = SHELL_SUCCESS;