From 4f77a2b044e97389ae683be5c8b870bf4b75ab72 Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Tue, 17 May 2016 20:43:32 +0200 Subject: [PATCH] #7500 buffer overflow: encodeMultiChar lib/mathlib.cpp:343. Improve errors handling --- lib/mathlib.cpp | 2 ++ test/testmathlib.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 6d98cbea9..dcccbe818 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -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); } diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index 8cc7258d1..ca569e103 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -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"));