[Scummvm-cvs-logs] SF.net SVN: scummvm:[55294] scummvm/trunk/engines/gob/variables.cpp

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Tue Jan 18 11:42:26 CET 2011


Revision: 55294
          http://scummvm.svn.sourceforge.net/scummvm/?rev=55294&view=rev
Author:   drmccoy
Date:     2011-01-18 10:42:26 +0000 (Tue, 18 Jan 2011)

Log Message:
-----------
GOB: Add some sanity checks

Modified Paths:
--------------
    scummvm/trunk/engines/gob/variables.cpp

Modified: scummvm/trunk/engines/gob/variables.cpp
===================================================================
--- scummvm/trunk/engines/gob/variables.cpp	2011-01-18 09:27:32 UTC (rev 55293)
+++ scummvm/trunk/engines/gob/variables.cpp	2011-01-18 10:42:26 UTC (rev 55294)
@@ -68,18 +68,27 @@
 }
 
 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 @@
 }
 
 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 {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list