]> git.lyx.org Git - features.git/commitdiff
Partial fix for bug 1474 (crashes on recursive includes) and complete fix for
authorRichard Heck <rgheck@comcast.net>
Mon, 21 May 2007 15:34:29 +0000 (15:34 +0000)
committerRichard Heck <rgheck@comcast.net>
Mon, 21 May 2007 15:34:29 +0000 (15:34 +0000)
bug 3659 (crash when file contains only an InsetInclude).

Added checks for self-inclusion. The reason this is not a complete fix is that
recursive input could arise from something other than self-inclusion. Checking
for that will be much more complicated, however.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18445 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/insets/InsetInclude.cpp

index c4c9e37a21b2369aa59822d941abeee52830dddc..f4088ae8ac904d1d195fceb8ef896a489d3b6268 100644 (file)
@@ -1621,7 +1621,10 @@ Buffer const * Buffer::getMasterBuffer() const
        if (!params().parentname.empty()
            && theBufferList().exists(params().parentname)) {
                Buffer const * buf = theBufferList().getBuffer(params().parentname);
-               if (buf)
+               //We need to check if the parent is us...
+               //FIXME RECURSIVE INCLUDE
+               //This is not sufficient, since recursive includes could be downstream.
+               if (buf && buf != this)
                        return buf->getMasterBuffer();
        }
 
index 8ec571d6051cc82678a94c4c5c8168ca633ec07d..968fa82e489becad97c56970122a0d51e168f3a7 100644 (file)
@@ -363,7 +363,12 @@ Buffer * getChildBuffer(Buffer const & buffer, InsetCommandParams const & params
        if (!isLyXFilename(included_file))
                return 0;
 
-       return theBufferList().getBuffer(included_file);
+       Buffer * childBuffer = theBufferList().getBuffer(included_file);
+       
+       //FIXME RECURSIVE INCLUDES
+       if (childBuffer == & buffer)
+               return 0;
+       else return childBuffer;
 }
 
 
@@ -405,6 +410,18 @@ int InsetInclude::latex(Buffer const & buffer, odocstream & os,
                return 0;
 
        FileName const included_file(includedFilename(buffer, params_));
+       
+       //Check we're not trying to include ourselves.
+       //FIXME RECURSIVE INCLUDE
+       //This isn't sufficient, as the inclusion could be downstream.
+       //But it'll have to do for now.
+       if (buffer.fileName() == included_file.toFilesystemEncoding()) {
+               Alert::error(_("Recursive input"), 
+                              bformat(_("Attempted to include file %1$s in itself! "
+                              "Ignoring inclusion."), from_utf8(incfile)));
+               return 0;
+       }
+
        Buffer const * const m_buffer = buffer.getMasterBuffer();
 
        // if incfile is relative, make it relative to the master
@@ -560,6 +577,17 @@ int InsetInclude::docbook(Buffer const & buffer, odocstream & os,
 
        string const included_file = includedFilename(buffer, params_).absFilename();
 
+       //Check we're not trying to include ourselves.
+       //FIXME RECURSIVE INCLUDE
+       //This isn't sufficient, as the inclusion could be downstream.
+       //But it'll have to do for now.
+       if (buffer.fileName() == included_file) {
+               Alert::error(_("Recursive input"), 
+                              bformat(_("Attempted to include file %1$s in itself! "
+                              "Ignoring inclusion."), from_utf8(incfile)));
+               return 0;
+       }
+
        // write it to a file (so far the complete file)
        string const exportfile = changeExtension(incfile, ".sgml");
        DocFileName writefile(changeExtension(included_file, ".sgml"));
@@ -629,7 +657,11 @@ void InsetInclude::validate(LaTeXFeatures & features) const
        if (loadIfNeeded(buffer, params_)) {
                // a file got loaded
                Buffer * const tmp = theBufferList().getBuffer(included_file);
-               if (tmp) {
+               // make sure the buffer isn't us
+               // FIXME RECURSIVE INCLUDES
+               // This is not sufficient, as recursive includes could be
+               // more than a file away. But it will do for now.
+               if (tmp && tmp != & buffer) {
                        // We must temporarily change features.buffer,
                        // otherwise it would always be the master buffer,
                        // and nested includes would not work.