public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Feng Tian <feng.tian@intel.com>
To: chao.b.zhang@intel.com
Cc: edk2-devel@lists.01.org
Subject: [patch] MdeModulePkg/FvSimpleFileSystem: fix assertions when FV is empty
Date: Tue,  2 Aug 2016 16:09:32 +0800	[thread overview]
Message-ID: <69491d04c14e4b41c46497b85100eeb7b54c71ab.1470125313.git.feng.tian@intel.com> (raw)

The original code will assert when dealing with those empty FVs.
The fix is used to solve this bug.

Cc: Chao Zhang <chao.b.zhang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Feng Tian <feng.tian@intel.com>
---
 .../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



             reply	other threads:[~2016-08-02  8:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-02  8:09 Feng Tian [this message]
2016-08-02 12:42 ` [patch] MdeModulePkg/FvSimpleFileSystem: fix assertions when FV is empty Zhang, Chao B

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=69491d04c14e4b41c46497b85100eeb7b54c71ab.1470125313.git.feng.tian@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox