diff options
| author | Sven Hesse | 2011-01-18 10:42:26 +0000 | 
|---|---|---|
| committer | Sven Hesse | 2011-01-18 10:42:26 +0000 | 
| commit | a6073a649a9cd9a363085297df1336ba71a1964d (patch) | |
| tree | 140314d73d48afea3beef8975133babdfd2b54e8 | |
| parent | efe0dea82c6c8fcbf4a50b950af2bf9cf82092d0 (diff) | |
| download | scummvm-rg350-a6073a649a9cd9a363085297df1336ba71a1964d.tar.gz scummvm-rg350-a6073a649a9cd9a363085297df1336ba71a1964d.tar.bz2 scummvm-rg350-a6073a649a9cd9a363085297df1336ba71a1964d.zip | |
GOB: Add some sanity checks
svn-id: r55294
| -rw-r--r-- | engines/gob/variables.cpp | 19 | 
1 files changed, 18 insertions, 1 deletions
| diff --git a/engines/gob/variables.cpp b/engines/gob/variables.cpp index 7f7ddb023d..94cfadb9a0 100644 --- a/engines/gob/variables.cpp +++ b/engines/gob/variables.cpp @@ -68,18 +68,27 @@ void Variables::writeVarString(uint32 var, const char *value) {  }  void Variables::writeOff8(uint32 offset, uint8 value) { +	assert(offset < _size); +  	write8(_vars + offset, value);  }  void Variables::writeOff16(uint32 offset, uint16 value) { +	assert((offset + 1) < _size); +  	write16(_vars + offset, value);  }  void Variables::writeOff32(uint32 offset, uint32 value) { +	assert((offset + 3) < _size); +  	write32(_vars + offset, value);  }  void Variables::writeOffString(uint32 offset, const char *value) { +	uint32 length = strlen(value); +	assert((offset + length + 1) < _size); +  	strcpy((char *)(_vars + offset), value);  } @@ -100,19 +109,27 @@ void Variables::readVarString(uint32 var, char *value, uint32 length) {  }  uint8 Variables::readOff8(uint32 offset) const { +	assert(offset < _size); +  	return read8(_vars + offset);  }  uint16 Variables::readOff16(uint32 offset) const { +	assert((offset + 1) < _size); +  	return read16(_vars + offset);  }  uint32 Variables::readOff32(uint32 offset) const { +	assert((offset + 3) < _size); +  	return read32(_vars + offset);  }  void Variables::readOffString(uint32 offset, char *value, uint32 length) { -	Common::strlcpy(value, (const char *)(_vars + offset), length); +	assert(offset < _size); + +	Common::strlcpy(value, (const char *)(_vars + offset), MIN<int>(length, _size - offset));  }  const uint8 *Variables::getAddressVar8(uint32 var) const { | 
