@@ -971,14 +971,18 @@ static void skipArrayScalars( const char * buf,
971
971
* @param[in,out] start The index at which to begin.
972
972
* @param[in] max The size of the buffer.
973
973
*
974
+ * @return true if a valid scalar key-value pairs were present;
975
+ * false otherwise.
976
+ *
974
977
* @note Stops advance if a value is an object or array.
975
978
*/
976
- static void skipObjectScalars ( const char * buf ,
979
+ static bool skipObjectScalars ( const char * buf ,
977
980
size_t * start ,
978
981
size_t max )
979
982
{
980
983
size_t i = 0U ;
981
984
bool comma = false;
985
+ bool ret = true;
982
986
983
987
coreJSON_ASSERT ( ( buf != NULL ) && ( start != NULL ) && ( max > 0U ) );
984
988
@@ -988,13 +992,15 @@ static void skipObjectScalars( const char * buf,
988
992
{
989
993
if ( skipString ( buf , & i , max ) != true )
990
994
{
995
+ ret = false;
991
996
break ;
992
997
}
993
998
994
999
skipSpace ( buf , & i , max );
995
1000
996
1001
if ( ( i < max ) && ( buf [ i ] != ':' ) )
997
1002
{
1003
+ ret = false;
998
1004
break ;
999
1005
}
1000
1006
@@ -1009,6 +1015,7 @@ static void skipObjectScalars( const char * buf,
1009
1015
1010
1016
if ( skipAnyScalar ( buf , & i , max ) != true )
1011
1017
{
1018
+ ret = false;
1012
1019
break ;
1013
1020
}
1014
1021
@@ -1020,6 +1027,8 @@ static void skipObjectScalars( const char * buf,
1020
1027
break ;
1021
1028
}
1022
1029
}
1030
+
1031
+ return ret ;
1023
1032
}
1024
1033
1025
1034
/**
@@ -1029,13 +1038,17 @@ static void skipObjectScalars( const char * buf,
1029
1038
* @param[in,out] start The index at which to begin.
1030
1039
* @param[in] max The size of the buffer.
1031
1040
* @param[in] mode The first character of an array '[' or object '{'.
1041
+ *
1042
+ * @return true if a valid scalers were present;
1043
+ * false otherwise.
1032
1044
*/
1033
- static void skipScalars ( const char * buf ,
1045
+ static bool skipScalars ( const char * buf ,
1034
1046
size_t * start ,
1035
1047
size_t max ,
1036
1048
char mode )
1037
1049
{
1038
1050
bool modeIsOpenBracket = ( bool ) isOpenBracket_ ( mode );
1051
+ bool ret = true;
1039
1052
1040
1053
/* assert function may be implemented in macro using a # or ## operator.
1041
1054
* Using a local variable here to prevent macro replacement is subjected
@@ -1053,8 +1066,10 @@ static void skipScalars( const char * buf,
1053
1066
}
1054
1067
else
1055
1068
{
1056
- skipObjectScalars ( buf , start , max );
1069
+ ret = skipObjectScalars ( buf , start , max );
1057
1070
}
1071
+
1072
+ return ret ;
1058
1073
}
1059
1074
1060
1075
/**
@@ -1106,7 +1121,12 @@ static JSONStatus_t skipCollection( const char * buf,
1106
1121
}
1107
1122
1108
1123
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
+
1110
1130
break ;
1111
1131
1112
1132
case '}' :
@@ -1120,7 +1140,10 @@ static JSONStatus_t skipCollection( const char * buf,
1120
1140
if ( ( skipSpaceAndComma ( buf , & i , max ) == true ) &&
1121
1141
isOpenBracket_ ( stack [ depth ] ) )
1122
1142
{
1123
- skipScalars ( buf , & i , max , stack [ depth ] );
1143
+ if ( skipScalars ( buf , & i , max , stack [ depth ] ) != true )
1144
+ {
1145
+ ret = JSONIllegalDocument ;
1146
+ }
1124
1147
}
1125
1148
1126
1149
break ;
0 commit comments