@@ -971,14 +971,18 @@ static void skipArrayScalars( const char * buf,
971971 * @param[in,out] start The index at which to begin.
972972 * @param[in] max The size of the buffer.
973973 *
974+ * @return true if a valid scalar key-value pairs were present;
975+ * false otherwise.
976+ *
974977 * @note Stops advance if a value is an object or array.
975978 */
976- static void skipObjectScalars ( const char * buf ,
979+ static bool skipObjectScalars ( const char * buf ,
977980 size_t * start ,
978981 size_t max )
979982{
980983 size_t i = 0U ;
981984 bool comma = false;
985+ bool ret = true;
982986
983987 coreJSON_ASSERT ( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
984988
@@ -988,13 +992,15 @@ static void skipObjectScalars( const char * buf,
988992 {
989993 if ( skipString ( buf , & i , max ) != true )
990994 {
995+ ret = false;
991996 break ;
992997 }
993998
994999 skipSpace ( buf , & i , max );
9951000
9961001 if ( ( i < max ) && ( buf [ i ] != ':' ) )
9971002 {
1003+ ret = false;
9981004 break ;
9991005 }
10001006
@@ -1009,6 +1015,7 @@ static void skipObjectScalars( const char * buf,
10091015
10101016 if ( skipAnyScalar ( buf , & i , max ) != true )
10111017 {
1018+ ret = false;
10121019 break ;
10131020 }
10141021
@@ -1020,6 +1027,8 @@ static void skipObjectScalars( const char * buf,
10201027 break ;
10211028 }
10221029 }
1030+
1031+ return ret ;
10231032}
10241033
10251034/**
@@ -1029,13 +1038,17 @@ static void skipObjectScalars( const char * buf,
10291038 * @param[in,out] start The index at which to begin.
10301039 * @param[in] max The size of the buffer.
10311040 * @param[in] mode The first character of an array '[' or object '{'.
1041+ *
1042+ * @return true if a valid scalers were present;
1043+ * false otherwise.
10321044 */
1033- static void skipScalars ( const char * buf ,
1045+ static bool skipScalars ( const char * buf ,
10341046 size_t * start ,
10351047 size_t max ,
10361048 char mode )
10371049{
10381050 bool modeIsOpenBracket = ( bool ) isOpenBracket_ ( mode );
1051+ bool ret = true;
10391052
10401053 /* assert function may be implemented in macro using a # or ## operator.
10411054 * Using a local variable here to prevent macro replacement is subjected
@@ -1053,8 +1066,10 @@ static void skipScalars( const char * buf,
10531066 }
10541067 else
10551068 {
1056- skipObjectScalars ( buf , start , max );
1069+ ret = skipObjectScalars ( buf , start , max );
10571070 }
1071+
1072+ return ret ;
10581073}
10591074
10601075/**
@@ -1106,7 +1121,12 @@ static JSONStatus_t skipCollection( const char * buf,
11061121 }
11071122
11081123 stack [ depth ] = c ;
1109- skipScalars ( buf , & i , max , stack [ depth ] );
1124+
1125+ if ( skipScalars ( buf , & i , max , stack [ depth ] ) != true )
1126+ {
1127+ ret = JSONIllegalDocument ;
1128+ }
1129+
11101130 break ;
11111131
11121132 case '}' :
@@ -1120,7 +1140,10 @@ static JSONStatus_t skipCollection( const char * buf,
11201140 if ( ( skipSpaceAndComma ( buf , & i , max ) == true ) &&
11211141 isOpenBracket_ ( stack [ depth ] ) )
11221142 {
1123- skipScalars ( buf , & i , max , stack [ depth ] );
1143+ if ( skipScalars ( buf , & i , max , stack [ depth ] ) != true )
1144+ {
1145+ ret = JSONIllegalDocument ;
1146+ }
11241147 }
11251148
11261149 break ;
0 commit comments