Forráskód Böngészése

2008-10-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Fixed the bug that causes segmentation fault when accessing files which
	don't exist or are not included in --select-file option while
	validating chunk checksum.
	* src/MultiDiskAdaptor.cc
Tatsuhiro Tsujikawa 17 éve
szülő
commit
cdb5796615
2 módosított fájl, 25 hozzáadás és 0 törlés
  1. 7 0
      ChangeLog
  2. 18 0
      src/MultiDiskAdaptor.cc

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2008-10-22 Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Fixed the bug that causes segmentation fault when accessing files which
+	don't exist or are not included in --select-file option while
+	validating chunk checksum.
+	* src/MultiDiskAdaptor.cc
+
 2008-10-20 Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Fixed compiler warning.

+ 18 - 0
src/MultiDiskAdaptor.cc

@@ -372,6 +372,16 @@ findFirstDiskWriterEntry(const DiskWriterEntries& diskWriterEntries, off_t offse
   return first;
 }
 
+static void throwOnDiskWriterNotOpened(const SharedHandle<DiskWriterEntry>& e,
+				       off_t offset,
+				       const std::string& topDirPath)
+{
+  throw DlAbortEx
+    (StringFormat("DiskWriter for offset=%s, filename=%s is not opened.",
+		  Util::itos(offset).c_str(),
+		  e->getFilePath(topDirPath).c_str()).str());  
+}
+
 void MultiDiskAdaptor::writeData(const unsigned char* data, size_t len,
 				 off_t offset)
 {
@@ -384,6 +394,10 @@ void MultiDiskAdaptor::writeData(const unsigned char* data, size_t len,
 
     openIfNot(*i, &DiskWriterEntry::openFile, _cachedTopDirPath);
 
+    if(!(*i)->isOpen()) {
+      throwOnDiskWriterNotOpened(*i, offset+(len-rem), _cachedTopDirPath);
+    }
+
     (*i)->getDiskWriter()->writeData(data+(len-rem), writeLength, fileOffset);
     rem -= writeLength;
     fileOffset = 0;
@@ -405,6 +419,10 @@ ssize_t MultiDiskAdaptor::readData(unsigned char* data, size_t len, off_t offset
 
     openIfNot(*i, &DiskWriterEntry::openFile, _cachedTopDirPath);
 
+    if(!(*i)->isOpen()) {
+      throwOnDiskWriterNotOpened(*i, offset+(len-rem), _cachedTopDirPath);
+    }
+
     totalReadLength +=
       (*i)->getDiskWriter()->readData(data+(len-rem), readLength, fileOffset);
     rem -= readLength;