File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -206,6 +206,12 @@ const char* json_scan(const char* input) {
206206 };
207207}
208208
209+ bool json_valid (const char * input) {
210+ input = json_scan (input);
211+ input = json_scan_whitespace (input);
212+ return input && !*input;
213+ };
214+
209215bool json_decode_r (const char *& input, bool & value, adl_tag) {
210216 const char * i = json_scan_whitespace (input);
211217 if (!i) return false ;
Original file line number Diff line number Diff line change @@ -100,6 +100,8 @@ const char* json_scan_object(const char* input);
100100const char * json_scan_array (const char * input);
101101const char * json_scan (const char * input); // generic
102102
103+ bool json_valid (const char * input);
104+
103105
104106// json_encode_r implements encoding of specific objects. Add overloads to this
105107// function to support custom classes.
Original file line number Diff line number Diff line change @@ -124,6 +124,10 @@ namespace ToolFramework {
124124 }
125125
126126 bool Store::JsonParser (const char * input) {
127+ if (!json_valid (input)) return false ; // invalid JSON string
128+
129+ // We have validated input, so in the following `return false` should never
130+ // happen. We keep it, however, just in case.
127131 bool result = json_decode_object (
128132 input,
129133 [this ](const char *& input_, std::string key) -> bool {
@@ -165,8 +169,6 @@ namespace ToolFramework {
165169 );
166170 if (!result) return false ;
167171
168- input = json_scan_whitespace (input);
169- if (!input || *input) return false ; // junk at the end
170172 return true ;
171173 };
172174
You can’t perform that action at this time.
0 commit comments