#7500 buffer overflow: encodeMultiChar lib/mathlib.cpp:343. Improve errors handling

This commit is contained in:
Alexander Mai 2016-05-17 20:43:32 +02:00
parent 7453b641bd
commit 4f77a2b044
2 changed files with 3 additions and 0 deletions

View File

@ -356,6 +356,8 @@ MathLib::bigint MathLib::characterLiteralToLongNumber(const std::string& str)
// is implementation-defined.
// clang and gcc seem to use the following encoding: 'AB' as (('A' << 8) | 'B')
const std::string& normStr = normalizeCharacterLiteral(str);
if (normStr.empty())
throw InternalError(0, "Internal Error. MathLib::characterLiteralToLongNumber: Unhandled char constant '" + str + "'.");
return encodeMultiChar(normStr);
}

View File

@ -301,6 +301,7 @@ private:
ASSERT_EQUALS(0, MathLib::characterLiteralToLongNumber(std::string("")));
ASSERT_EQUALS(32, MathLib::characterLiteralToLongNumber(std::string(" ")));
ASSERT_EQUALS(538976288, MathLib::characterLiteralToLongNumber(std::string(" ")));
ASSERT_THROW(MathLib::characterLiteralToLongNumber(std::string("\\u")), InternalError);
}
ASSERT_EQUALS(-8552249625308161526, MathLib::toLongNumber("0x89504e470d0a1a0a"));