aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sandulenko2019-06-06 17:09:28 +0200
committerEugene Sandulenko2019-09-03 17:16:43 +0200
commit3533362fc85a71a2ba7597f77eec86bb4a997f4f (patch)
tree25ef2bf72aa4228a8542310f7ab234ce8983603f
parent341759cf0ddea26666bbdcdfd719bd830d51600a (diff)
downloadscummvm-rg350-3533362fc85a71a2ba7597f77eec86bb4a997f4f.tar.gz
scummvm-rg350-3533362fc85a71a2ba7597f77eec86bb4a997f4f.tar.bz2
scummvm-rg350-3533362fc85a71a2ba7597f77eec86bb4a997f4f.zip
HDB: Make sure there is no OOB access for patched scripts
-rw-r--r--engines/hdb/lua-script.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/engines/hdb/lua-script.cpp b/engines/hdb/lua-script.cpp
index 567a3b91a6..ec0848ce63 100644
--- a/engines/hdb/lua-script.cpp
+++ b/engines/hdb/lua-script.cpp
@@ -719,20 +719,21 @@ bool LuaScript::executeMPC(Common::SeekableReadStream *stream, const char *name,
return false;
}
- char *chunk = new char[length];
+ char *chunk = new char[length + 1];
stream->read((void *)chunk, length);
+ chunk[length] = '\0'; // be on the safe side
stripComments(chunk);
-
+
/*
Remove C-style comments from the script
and update the upvalue syntax for Lua 5.1.3
*/
- Common::String chunkString(chunk);
+ Common::String chunkString(chunk, length);
addPatches(chunkString, scriptName);
- if (!executeChunk(chunkString, length, name)) {
+ if (!executeChunk(chunkString, chunkString.size(), name)) {
delete[] chunk;
return false;
@@ -756,8 +757,9 @@ bool LuaScript::executeFile(const Common::String &filename) {
}
uint fileSize = file->size();
- char *fileData = new char[fileSize];
+ char *fileData = new char[fileSize + 1];
file->read((void *)fileData, fileSize);
+ fileData[fileSize] = '\0'; // be on the safe side
stripComments(fileData);
@@ -765,7 +767,7 @@ bool LuaScript::executeFile(const Common::String &filename) {
addPatches(fileDataString, filename.c_str());
- if (!executeChunk(fileDataString, fileSize, filename)) {
+ if (!executeChunk(fileDataString, fileDataString.size(), filename)) {
delete[] fileData;
delete file;