Skip to content

Commit 4c4f597

Browse files
author
czjaso
committed
Fix array parsing to reject missing commas between elements
1 parent 03a463f commit 4c4f597

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

source/core_json.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,11 +934,12 @@ static bool skipSpaceAndComma( const char * buf,
934934
*
935935
* @note Stops advance if a value is an object or array.
936936
*/
937-
static void skipArrayScalars( const char * buf,
937+
static bool skipArrayScalars( const char * buf,
938938
size_t * start,
939939
size_t max )
940940
{
941941
size_t i = 0U;
942+
bool ret = true;
942943

943944
coreJSON_ASSERT( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
944945

@@ -953,11 +954,18 @@ static void skipArrayScalars( const char * buf,
953954

954955
if( skipSpaceAndComma( buf, &i, max ) != true )
955956
{
957+
/* After parsing a scalar, we must either have a comma (followed by more content)
958+
* or be at a closing bracket. If neither, the array is malformed. */
959+
if( ( i >= max ) || !isSquareClose_( buf[ i ] ) )
960+
{
961+
ret = false;
962+
}
956963
break;
957964
}
958965
}
959966

960967
*start = i;
968+
return ret;
961969
}
962970

963971
/**
@@ -1071,7 +1079,7 @@ static bool skipScalars( const char * buf,
10711079
{
10721080
if( !isSquareClose_( buf[ i ] ) )
10731081
{
1074-
skipArrayScalars( buf, start, max );
1082+
ret = skipArrayScalars( buf, start, max );
10751083
}
10761084
}
10771085
else

0 commit comments

Comments
 (0)