diff options
author | Alyssa Milburn | 2011-07-02 00:03:49 +0200 |
---|---|---|
committer | Alyssa Milburn | 2011-07-02 00:03:49 +0200 |
commit | 689099f9b5d93e901f4adcc24c63f7a377a33fdb (patch) | |
tree | 4b8d251c71f39e2b5d2d95ecc05fc9b93dff3201 /engines/mohawk | |
parent | 23dd778a16bd610cce0a3fbc3b37543c0e75e6dd (diff) | |
download | scummvm-rg350-689099f9b5d93e901f4adcc24c63f7a377a33fdb.tar.gz scummvm-rg350-689099f9b5d93e901f4adcc24c63f7a377a33fdb.tar.bz2 scummvm-rg350-689099f9b5d93e901f4adcc24c63f7a377a33fdb.zip |
MOHAWK: Fix/add bounds checking in LBCode::nextToken.
Diffstat (limited to 'engines/mohawk')
-rw-r--r-- | engines/mohawk/livingbooks_code.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/engines/mohawk/livingbooks_code.cpp b/engines/mohawk/livingbooks_code.cpp index e72318d86a..96345ad845 100644 --- a/engines/mohawk/livingbooks_code.cpp +++ b/engines/mohawk/livingbooks_code.cpp @@ -172,12 +172,8 @@ LBValue LBCode::runCode(LBItem *src, uint32 offset) { } void LBCode::nextToken() { - if (_currOffset + 1 >= _size) { - // TODO - warning("went off the end of code"); - _currToken = kTokenEndOfFile; - _currValue = LBValue(); - return; + if (_currOffset >= _size) { + error("went off the end of code"); } _currToken = _data[_currOffset++]; @@ -186,6 +182,8 @@ void LBCode::nextToken() { switch (_currToken) { case kTokenIdentifier: { + if (_currOffset + 2 > _size) + error("went off the end of code reading identifier"); uint16 offset = READ_BE_UINT16(_data + _currOffset); // TODO: check string exists _currValue = _strings[offset]; @@ -195,9 +193,13 @@ void LBCode::nextToken() { case kTokenLiteral: { + if (_currOffset + 1 > _size) + error("went off the end of code reading literal"); byte literalType = _data[_currOffset++]; switch (literalType) { case kLBCodeLiteralInteger: + if (_currOffset + 2 > _size) + error("went off the end of code reading literal integer"); _currValue = READ_BE_UINT16(_data + _currOffset); _currOffset += 2; break; @@ -211,6 +213,8 @@ void LBCode::nextToken() { case kTokenConstEventId: case 0x5e: // TODO: ?? case kTokenKeycode: + if (_currOffset + 2 > _size) + error("went off the end of code reading immediate"); _currValue = READ_BE_UINT16(_data + _currOffset); _currOffset += 2; break; @@ -227,6 +231,8 @@ void LBCode::nextToken() { case kTokenString: { + if (_currOffset + 2 > _size) + error("went off the end of code reading string"); uint16 offset = READ_BE_UINT16(_data + _currOffset); // TODO: check string exists _currValue = _strings[offset]; |