From: Richard Heck Date: Fri, 23 May 2014 15:19:14 +0000 (-0400) Subject: Improve the fix for #9131. We were previously counting passes X-Git-Tag: 2.1.1~44 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=5579d3734a3b7f3c6b7332c6989701a8a224bbf1;p=features.git Improve the fix for #9131. We were previously counting passes through this routine, which means: one for every character, more or less. So long strings would hit the "recursion limit". But what we are worried about is an infinite loop caused by misues of macros, so that is what we need to count. --- diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp index ddd2486b1f..55d65deb4e 100644 --- a/src/BiblioInfo.cpp +++ b/src/BiblioInfo.cpp @@ -488,7 +488,7 @@ docstring BibTeXInfo::expandFormat(docstring const & format, // we'll remove characters from the front of fmt as we // deal with them while (!fmt.empty()) { - if (counter++ > max_passes) { + if (counter > max_passes) { LYXERR0("Recursion limit reached while parsing `" << format << "'."); return _("ERROR!"); @@ -506,6 +506,7 @@ docstring BibTeXInfo::expandFormat(docstring const & format, string const val = buf.params().documentClass().getCiteMacro(engine_type, key); fmt = from_utf8(val) + fmt.substr(1); + counter += 1; continue; } else if (key[0] == '_') { // a translatable bit @@ -550,12 +551,15 @@ docstring BibTeXInfo::expandFormat(docstring const & format, getValueForKey(optkey, buf, before, after, dialog, xref); if (optkey == "next" && next) ret << ifpart; // without expansion - else if (!val.empty()) - ret << expandFormat(ifpart, xref, counter, buf, + else if (!val.empty()) { + int newcounter = 0; + ret << expandFormat(ifpart, xref, newcounter, buf, before, after, dialog, next); - else if (!elsepart.empty()) - ret << expandFormat(elsepart, xref, counter, buf, + } else if (!elsepart.empty()) { + int newcounter = 0; + ret << expandFormat(elsepart, xref, newcounter, buf, before, after, dialog, next); + } // fmt will have been shortened for us already continue; }