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 <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Jaben Carsey <jaben.carsey@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
This commit is contained in:
Jiaxin Wu 2018-04-26 14:13:57 +08:00 committed by Jiaxin Wu
parent 0c6f94dae5
commit 280f49b811
1 changed files with 2 additions and 1 deletions

View File

@ -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;