From 46ed83037312051d5c7046db940eddf58e1b5206 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Thu, 21 Jan 2016 15:29:41 -0500 Subject: [PATCH] variant.cpp: Tighten bool parsing in variant::as_bool() cryptonomex/graphene#525 --- src/variant.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/variant.cpp b/src/variant.cpp index 7b73771..542ee66 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -431,7 +431,14 @@ bool variant::as_bool()const switch( get_type() ) { case string_type: - return **reinterpret_cast(this) == "true"; + { + const string& s = **reinterpret_cast(this); + if( s == "true" ) + return true; + if( s == "false" ) + return false; + FC_THROW_EXCEPTION( bad_cast_exception, "Cannot convert string to bool (only \"true\" or \"false\" can be converted)" ); + } case double_type: return *reinterpret_cast(this) != 0.0; case int64_type: