From 98dcd883e4ee1b3d62a1b9e7d4e5d4e038ea0434 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Tue, 8 Nov 2016 13:37:59 +0100 Subject: codegen: check the value range after converting something to an enum element --- libsolidity/codegen/CompilerUtils.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libsolidity') diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index e064c1a6..5e045996 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -656,6 +656,14 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp solAssert(_typeOnStack == _targetType, "Invalid type conversion requested."); break; } + + // Check the conversion result fits in a range. + if (targetTypeCategory == Type::Category::Enum) + { + EnumType const& enumType = dynamic_cast(_targetType); + m_context << u256(enumType.numberOfMembers()) << Instruction::DUP2 << Instruction::LT << Instruction::ISZERO; + m_context.appendConditionalJumpTo(m_context.errorTag()); + } } void CompilerUtils::pushZeroValue(Type const& _type) -- cgit