From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7BB52211F889D for ; Wed, 11 Jul 2018 17:44:16 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jul 2018 17:44:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,339,1526367600"; d="scan'208";a="54373667" Received: from jiaxinwu-mobl.ccr.corp.intel.com ([10.239.192.131]) by fmsmga008.fm.intel.com with ESMTP; 11 Jul 2018 17:44:14 -0700 From: Jiaxin Wu To: edk2-devel@lists.01.org Cc: Jiaxin Wu , Ye Ting , Fu Siyuan , Jaben Carsey Date: Thu, 12 Jul 2018 08:44:10 +0800 Message-Id: <20180712004410.13324-1-Jiaxin.wu@intel.com> X-Mailer: git-send-email 2.17.1.windows.2 Subject: [Patch] ShellPkg/TftpDynamicCommand: Fix the potential assertion and memory leak issue. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Jul 2018 00:44:16 -0000 From: Jiaxin Wu 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 --- ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 @@ -517,10 +517,12 @@ RunTftp ( mTftpHiiHandle, RemoteFilePath, NicName, Status ); goto NextHandle; } + DataSize = FileSize; + if (!EFI_ERROR (ShellFileExists (LocalFilePath))) { ShellDeleteFileByName (LocalFilePath); } Status = ShellOpenFileByName ( @@ -537,11 +539,10 @@ RunTftp ( mTftpHiiHandle, L"tftp", LocalFilePath ); goto NextHandle; } - DataSize = FileSize; Status = ShellWriteFile (FileHandle, &FileSize, Data); if (!EFI_ERROR (Status)) { ShellStatus = SHELL_SUCCESS; } else { ShellPrintHiiEx ( -- 2.17.1.windows.2