Lack of error checking after have_document() in preview case could lead to looping, and cancellation was not checked to make things worse

This commit is contained in:
dockes 2009-11-16 16:18:04 +00:00
parent 9ead4bbbe9
commit 120cf441ba

View File

@ -46,6 +46,7 @@ using namespace std;
#include "mh_html.h" #include "mh_html.h"
#include "fileudi.h" #include "fileudi.h"
#include "beaglequeue.h" #include "beaglequeue.h"
#include "cancelcheck.h"
#ifdef RCL_USE_XATTR #ifdef RCL_USE_XATTR
#include "pxattr.h" #include "pxattr.h"
@ -758,6 +759,7 @@ FileInterner::Status FileInterner::internfile(Rcl::Doc& doc, string& ipath)
// security in the form of a maximum handler stack size. // security in the form of a maximum handler stack size.
int loop = 0; int loop = 0;
while (!m_handlers.empty()) { while (!m_handlers.empty()) {
CancelCheck::instance().checkCancel();
if (loop++ > 1000) { if (loop++ > 1000) {
LOGERR(("FileInterner:: looping!\n")); LOGERR(("FileInterner:: looping!\n"));
return FIError; return FIError;
@ -765,6 +767,15 @@ FileInterner::Status FileInterner::internfile(Rcl::Doc& doc, string& ipath)
// If there are no more docs at the current top level we pop and // If there are no more docs at the current top level we pop and
// see if there is something at the previous one // see if there is something at the previous one
if (!m_handlers.back()->has_documents()) { if (!m_handlers.back()->has_documents()) {
// If looking for a specific doc, this is an error. Happens if
// the index is stale, and the ipath points to the wrong message
// for exemple (one with less attachments)
if (m_forPreview) {
m_reason += "Requested document does not exist. ";
m_reason += m_handlers.back()->get_error();
LOGERR(("FileInterner: requested document does not exist\n"));
return FIError;
}
popHandler(); popHandler();
continue; continue;
} }
@ -774,8 +785,12 @@ FileInterner::Status FileInterner::internfile(Rcl::Doc& doc, string& ipath)
// still want to process the rest of the mbox! For preview: fatal. // still want to process the rest of the mbox! For preview: fatal.
if (!m_handlers.back()->next_document()) { if (!m_handlers.back()->next_document()) {
processNextDocError(doc, ipath); processNextDocError(doc, ipath);
if (m_forPreview) if (m_forPreview) {
m_reason += "Requested document does not exist. ";
m_reason += m_handlers.back()->get_error();
LOGERR(("FileInterner: requested document does not exist\n"));
return FIError; return FIError;
}
popHandler(); popHandler();
continue; continue;
} }