From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by ml01.01.org (Postfix) with ESMTP id E4DDE1A1E12 for ; Tue, 2 Aug 2016 01:09:35 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 02 Aug 2016 01:09:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,459,1464678000"; d="scan'208";a="1018101377" Received: from shwdeftian.ccr.corp.intel.com ([10.239.158.36]) by fmsmga001.fm.intel.com with ESMTP; 02 Aug 2016 01:09:35 -0700 From: Feng Tian To: chao.b.zhang@intel.com Cc: edk2-devel@lists.01.org Date: Tue, 2 Aug 2016 16:09:32 +0800 Message-Id: <69491d04c14e4b41c46497b85100eeb7b54c71ab.1470125313.git.feng.tian@intel.com> X-Mailer: git-send-email 2.7.1.windows.2 Subject: [patch] MdeModulePkg/FvSimpleFileSystem: fix assertions when FV is empty X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Aug 2016 08:09:36 -0000 The original code will assert when dealing with those empty FVs. The fix is used to solve this bug. Cc: Chao Zhang Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Feng Tian --- .../Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c | 9 +++++++-- .../FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c | 6 +++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c index c6137ac..b81110f 100644 --- a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c +++ b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c @@ -526,7 +526,10 @@ FvSimpleFileSystemOpen ( InitializeListHead (&NewFile->Link); InsertHeadList (&Instance->FileHead, &NewFile->Link); - NewFile->DirReadNext = FVFS_GET_FIRST_FILE_INFO (Instance); + NewFile->DirReadNext = NULL; + if (!IsListEmpty (&Instance->FileInfoHead)) { + NewFile->DirReadNext = FVFS_GET_FIRST_FILE_INFO (Instance); + } *NewHandle = &NewFile->FileProtocol; return EFI_SUCCESS; @@ -821,7 +824,9 @@ FvSimpleFileSystemSetPosition ( // // Reset directory position to first entry // - File->DirReadNext = FVFS_GET_FIRST_FILE_INFO (Instance); + if (File->DirReadNext) { + File->DirReadNext = FVFS_GET_FIRST_FILE_INFO (Instance); + } } else if (Position == 0xFFFFFFFFFFFFFFFFull) { File->Position = File->FvFileInfo->FileInfo.FileSize; } else { diff --git a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c index 7167fb9..4e6089b 100644 --- a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c +++ b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c @@ -223,7 +223,11 @@ FvSimpleFileSystemOpenVolume ( } } - Instance->Root->DirReadNext = FVFS_GET_FIRST_FILE_INFO (Instance); + Instance->Root->DirReadNext = NULL; + if (!IsListEmpty (&Instance->FileInfoHead)) { + Instance->Root->DirReadNext = FVFS_GET_FIRST_FILE_INFO (Instance); + } + *RootFile = &Instance->Root->FileProtocol; return Status; } -- 2.7.1.windows.2