Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
don't fall into forever loop in zero byty in json #3500
Browse files Browse the repository at this point in the history
  • Loading branch information
moskvanaft committed May 28, 2018
1 parent 0a93e47 commit a5f1a20
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions libraries/fc/src/io/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 == '/' )
{
Expand Down Expand Up @@ -263,10 +267,9 @@ namespace fc

try
{
char c;
while((c = in.peek()) && !done)
while( !done )
{

char c = in.peek();
switch( c )
{
case '.':
Expand All @@ -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 ) )
{
Expand Down Expand Up @@ -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 ' ':
Expand Down Expand Up @@ -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}\"",
Expand Down

1 comment on commit a5f1a20

@abitmore
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are more issues in this file. Check bitshares/bitshares-fc#15, bitshares/bitshares-fc#21 and etc.

Please sign in to comment.