Hi,

I am working on BibleTime for Windows and we found and fixed a crash in the sword library. I have attached a patch for the HEAD of sword svn. We are using the 1.60 version of sword.

The crash occurs when trying to save to a personal commentary for the first time. Sword is looking for the "incfile" of the personal commentary. The file does not exist yet.. Here is the call stack and function at the crash point.

libsword.dll!sword::FileDesc::read(void * buf=0x013eaec0, long count=4) Line 139
libsword.dll!sword::RawFiles::getNextFilename()  Line 194
libsword.dll!sword::RawFiles::setEntry(const char * inbuf=0x0253d050, long len=3) Line 130 bibletime.exe!CSwordModuleInfo::write(CSwordKey * key=0x02e6cd00, const QString & newText={...}) Line 705

long FileDesc::read(void *buf, long count) {
  return ::read(getFd(), buf, count);       // crash here
}

Since the file does not exist, getFd() returns a fd of -1. The read promptly crashes with the negative fd. Tracing the same problem in linux shows the same -1 fd, but the read does not crash there. The crash seems specific to the Visual Studio 2008 runtime libraries, but reading with a negative fd value is clearly wrong.

The fix is simple. Test for the negative fd and return 0 from fileDesc::read if fd is negative. Returning 0 is what is happening on linux.

Gary Holmlund

Index: src/mgr/filemgr.cpp
===================================================================
--- src/mgr/filemgr.cpp (revision 2457)
+++ src/mgr/filemgr.cpp (working copy)
@@ -136,7 +136,11 @@
 
 
 long FileDesc::read(void *buf, long count) {
-       return ::read(getFd(), buf, count);
+       int fd = getFd();
+       if (fd < 0) {
+               return 0;
+       }
+       return ::read(fd, buf, count);
 }
 
 
_______________________________________________
sword-devel mailing list: sword-devel@crosswire.org
http://www.crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page

Reply via email to