Skip to content

Commit 4f77a2b

Browse files
committed
danmar#7500 buffer overflow: encodeMultiChar lib/mathlib.cpp:343. Improve errors handling
1 parent 7453b64 commit 4f77a2b

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

lib/mathlib.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ MathLib::bigint MathLib::characterLiteralToLongNumber(const std::string& str)
356356
// is implementation-defined.
357357
// clang and gcc seem to use the following encoding: 'AB' as (('A' << 8) | 'B')
358358
const std::string& normStr = normalizeCharacterLiteral(str);
359+
if (normStr.empty())
360+
throw InternalError(0, "Internal Error. MathLib::characterLiteralToLongNumber: Unhandled char constant '" + str + "'.");
359361
return encodeMultiChar(normStr);
360362
}
361363

test/testmathlib.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ class TestMathLib : public TestFixture {
301301
ASSERT_EQUALS(0, MathLib::characterLiteralToLongNumber(std::string("")));
302302
ASSERT_EQUALS(32, MathLib::characterLiteralToLongNumber(std::string(" ")));
303303
ASSERT_EQUALS(538976288, MathLib::characterLiteralToLongNumber(std::string(" ")));
304+
ASSERT_THROW(MathLib::characterLiteralToLongNumber(std::string("\\u")), InternalError);
304305
}
305306

306307
ASSERT_EQUALS(-8552249625308161526, MathLib::toLongNumber("0x89504e470d0a1a0a"));

0 commit comments

Comments
 (0)