From a5f1a208acc3dcb926c28697cf3be316f21ab7e7 Mon Sep 17 00:00:00 2001 From: Anton Perkov Date: Mon, 28 May 2018 16:19:35 -0400 Subject: [PATCH] don't fall into forever loop in zero byty in json #3500 --- libraries/fc/src/io/json.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/libraries/fc/src/io/json.cpp b/libraries/fc/src/io/json.cpp index 5980cbf732d..281634c3853 100644 --- a/libraries/fc/src/io/json.cpp +++ b/libraries/fc/src/io/json.cpp @@ -77,6 +77,9 @@ namespace fc skipped = true; in.get(); break; + case '\0': + FC_THROW_EXCEPTION( eof_exception, "unexpected end of file" ); + break; default: return skipped; } @@ -136,10 +139,11 @@ namespace fc break; case '\t': case ' ': - case '\0': case '\n': in.get(); return token.str(); + case '\0': + FC_THROW_EXCEPTION( eof_exception, "unexpected end of file" ); default: if( isalnum( c ) || c == '_' || c == '-' || c == '.' || c == ':' || c == '/' ) { @@ -263,10 +267,9 @@ namespace fc try { - char c; - while((c = in.peek()) && !done) + while( !done ) { - + char c = in.peek(); switch( c ) { case '.': @@ -285,6 +288,8 @@ namespace fc case '9': ss.put( in.get() ); break; + case '\0': + FC_THROW_EXCEPTION( eof_exception, "unexpected end of file" ); default: if( isalnum( c ) ) { @@ -387,8 +392,9 @@ namespace fc { skip_white_space(in); variant var; - while( signed char c = in.peek() ) + while( 1 ) { + signed char c = in.peek(); switch( c ) { case ' ': @@ -423,7 +429,7 @@ namespace fc return token_from_stream( in ); case 0x04: // ^D end of transmission case EOF: - case 0: + case '\0': FC_THROW_EXCEPTION( eof_exception, "unexpected end of file" ); default: FC_THROW_EXCEPTION( parse_error_exception, "Unexpected char '${c}' in \"${s}\"",