From 057eef07bbddb3500dedebe2fd523ac67e538541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Harabie=C5=84?= Date: Sat, 7 Oct 2017 02:16:34 +0200 Subject: [PATCH] Fix possible deadlock if reading dir entry fails. --- src/dir.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/dir.rs b/src/dir.rs index 1d9d21e..4a07295 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -238,6 +238,7 @@ impl <'a, 'b> FatDir<'a, 'b> { FatDirIter { rdr: self.rdr.clone(), fs: self.fs.clone(), + err: false, } } @@ -281,6 +282,7 @@ impl <'a, 'b> FatDir<'a, 'b> { pub struct FatDirIter<'a, 'b: 'a> { rdr: FatDirReader<'a, 'b>, fs: FatFileSystemRef<'a, 'b>, + err: bool, } impl <'a, 'b> FatDirIter<'a, 'b> { @@ -325,12 +327,18 @@ impl <'a, 'b> Iterator for FatDirIter<'a, 'b> { type Item = io::Result>; fn next(&mut self) -> Option { + if self.err { + return None; + } let mut lfn_buf = Vec::::new(); loop { let res = self.read_dir_entry_data(); let data = match res { Ok(data) => data, - Err(err) => return Some(Err(err)), + Err(err) => { + self.err = true; + return Some(Err(err)); + }, }; match data { FatDirEntryData::File(data) => {