summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2016-05-30 21:03:11 +0000
committerfrosch <frosch@openttd.org>2016-05-30 21:03:11 +0000
commita2edf52b418743dc82a823ef1d65870584af4d4a (patch)
treee90952d4ab12f0987fe733bc1cc0e2c408d8eb28
parentd90686f0217c2ad8dfc814694b7b9ea578dd7a49 (diff)
downloadopenttd-a2edf52b418743dc82a823ef1d65870584af4d4a.tar.xz
(svn r27594) -Fix [FS#6473]: [Script] Kill scripts, when a non-suspendable valuator call takes way too long.
-rw-r--r--src/script/api/script_list.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/script/api/script_list.cpp b/src/script/api/script_list.cpp
index bdbc1209b..d0c72b5bb 100644
--- a/src/script/api/script_list.cpp
+++ b/src/script/api/script_list.cpp
@@ -11,6 +11,7 @@
#include "../../stdafx.h"
#include "script_list.hpp"
+#include "script_controller.hpp"
#include "../../debug.h"
#include "../../script/squirrel.hpp"
@@ -905,6 +906,16 @@ SQInteger ScriptList::Valuate(HSQUIRRELVM vm)
}
}
+ /* Kill the script when the valuator call takes way too long.
+ * Triggered by nesting valuators, which then take billions of iterations. */
+ if (ScriptController::GetOpsTillSuspend() < -1000000) {
+ /* See below for explanation. The extra pop is the return value. */
+ sq_pop(vm, nparam + 4);
+
+ ScriptObject::SetAllowDoCommand(backup_allow);
+ return sq_throwerror(vm, "excessive CPU usage in valuator function");
+ }
+
/* Was something changed? */
if (previous_modification_count != this->modifications) {
/* See below for explanation. The extra pop is the return value. */