]> git.lyx.org Git - features.git/commitdiff
Make LFUN_REPEAT more robust by limiting to 10000 iterations
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 28 Mar 2017 09:30:18 +0000 (11:30 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 28 Mar 2017 09:30:18 +0000 (11:30 +0200)
src/LyXAction.cpp
src/frontends/qt4/GuiApplication.cpp

index 3cccc3787e1571cdec37751cadbc27d4736909e3..bb3bf3e34030decca1f22b6cb5b926835581b556 100644 (file)
@@ -3262,6 +3262,7 @@ void LyXAction::init()
 /*!
  * \var lyx::FuncCode lyx::LFUN_REPEAT
  * \li Action: Repeat the given command.
+ * \li Notion: fails when the repeat count is greater than 10000.
  * \li Syntax: repeat <COUNT> <LFUN-COMMAND>
  * \li Origin: Andre, 27 Oct 2003
  * \endvar
index c27f4c87e3a032147b335bce36fba34158213922..3a0c6013b1f829158f04e5ab486ea7014a9ee9b4 100644 (file)
@@ -1858,8 +1858,15 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                string countstr;
                string rest = split(argument, countstr, ' ');
                int const count = convert<int>(countstr);
-               for (int i = 0; i < count; ++i)
-                       dispatch(lyxaction.lookupFunc(rest));
+               // an arbitrary number to limit number of iterations
+               int const max_iter = 10000;
+               if (count > max_iter) {
+                       dr.setMessage(bformat(_("Cannot iterate more than %1$d times"), max_iter));
+                       dr.setError(true);
+               } else {
+                       for (int i = 0; i < count; ++i)
+                               dispatch(lyxaction.lookupFunc(rest));
+               }
                break;
        }