summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-09-03 11:48:08 +0000
committerrubidium <rubidium@openttd.org>2009-09-03 11:48:08 +0000
commit5607a610d7b5ebb93af90d64ee1a8098fb94df06 (patch)
tree265c5e23c1669e4d4813ccc2d2ced8572de5e96e /src
parent48e1a5a350a969957617d86cdcc2465db63815f5 (diff)
downloadopenttd-5607a610d7b5ebb93af90d64ee1a8098fb94df06.tar.xz
(svn r17403) -Fix [Squirrel]: guard against squirrel stack overflows; if assert is enabled assert (catch possible overflow bugs in nightlies/RCs), otherwise just increase the stack's size (don't get into invalid reads/writes in releases)
Diffstat (limited to 'src')
-rw-r--r--src/3rdparty/squirrel/squirrel/squtils.h2
-rw-r--r--src/3rdparty/squirrel/squirrel/sqvm.cpp14
2 files changed, 14 insertions, 2 deletions
diff --git a/src/3rdparty/squirrel/squirrel/squtils.h b/src/3rdparty/squirrel/squirrel/squtils.h
index b6a436e4a..55febe38c 100644
--- a/src/3rdparty/squirrel/squirrel/squtils.h
+++ b/src/3rdparty/squirrel/squirrel/squtils.h
@@ -88,7 +88,7 @@ public:
}
SQUnsignedInteger capacity() { return _allocated; }
inline T &back() const { return _vals[_size - 1]; }
- inline T& operator[](SQUnsignedInteger pos) const{ return _vals[pos]; }
+ inline T& operator[](SQUnsignedInteger pos) const{ assert(pos < _allocated); return _vals[pos]; }
T* _vals;
private:
void _realloc(SQUnsignedInteger newsize)
diff --git a/src/3rdparty/squirrel/squirrel/sqvm.cpp b/src/3rdparty/squirrel/squirrel/sqvm.cpp
index 2c277d996..720f21297 100644
--- a/src/3rdparty/squirrel/squirrel/sqvm.cpp
+++ b/src/3rdparty/squirrel/squirrel/sqvm.cpp
@@ -1526,7 +1526,19 @@ void SQVM::Pop(SQInteger n) {
}
}
-void SQVM::Push(const SQObjectPtr &o) { _stack[_top++] = o; }
+void SQVM::Push(const SQObjectPtr &o) {
+ /* Normally the stack shouldn't get this full, sometimes it might. As of now
+ * all cases have been bugs in "our" (OpenTTD) code. Trigger an assert for
+ * all debug builds and for the release builds just increase the stack size.
+ * This way getting a false positive isn't that bad (releases work fine) and
+ * if there is something fishy it can be caught in RCs/nightlies. */
+#ifdef NDEBUG
+ if (_top >= (int)_stack.capacity()) _stack.resize(2 * _stack.capacity());
+#else
+ assert(_top < (int)_stack.capacity());
+#endif
+ _stack[_top++] = o;
+}
SQObjectPtr &SQVM::Top() { return _stack[_top-1]; }
SQObjectPtr &SQVM::PopGet() { return _stack[--_top]; }
SQObjectPtr &SQVM::GetUp(SQInteger n) { return _stack[_top+n]; }