Skip to content

Commit 629f085

Browse files
author
Evgenii Zhemchugov
committed
Store::JsonParser: validate input before parsing
Avoid leaving Store half-filled.
1 parent ce36831 commit 629f085

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/Store/Store.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ namespace ToolFramework {
124124
}
125125

126126
bool Store::JsonParser(const char* input) {
127+
const char* s = json_scan(input);
128+
s = json_scan_whitespace(s);
129+
if (!s || *s) return false; // invalid JSON string
130+
131+
// We have validated input, so in the following `return false` should never
132+
// happen. We keep it, however, just in case.
127133
bool result = json_decode_object(
128134
input,
129135
[this](const char*& input_, std::string key) -> bool {
@@ -165,8 +171,6 @@ namespace ToolFramework {
165171
);
166172
if (!result) return false;
167173

168-
input = json_scan_whitespace(input);
169-
if (!input || *input) return false; // junk at the end
170174
return true;
171175
};
172176

0 commit comments

Comments
 (0)