Made two security fixes.

This commit is contained in:
Aaron Jacobs
2011-05-24 00:43:59 +00:00
parent 785ba2675d
commit a77a803c85
2 changed files with 11 additions and 0 deletions

View File

@@ -56,6 +56,12 @@ duplicateStringValue( const char *value,
{
if ( length == unknown )
length = (unsigned int)strlen(value);
// Avoid an integer overflow in the call to malloc below by limiting length
// to a sane value.
if (length >= (unsigned)Value::maxInt)
length = Value::maxInt - 1;
char *newString = static_cast<char *>( malloc( length + 1 ) );
JSON_ASSERT_MESSAGE( newString != 0, "Failed to allocate string value buffer" );
memcpy( newString, value, length );