Check for unterminated strings properly
Also, public to enable fuzzing. This was the first catch!
This commit is contained in:
parent
9b0a39fa90
commit
77cbf1700f
4 changed files with 11 additions and 5 deletions
|
|
@ -77,7 +77,7 @@ async fn list_containers() -> Result<Vec<u8>> {
|
|||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum JsonValue {
|
||||
pub enum JsonValue {
|
||||
Null,
|
||||
True,
|
||||
False,
|
||||
|
|
@ -207,7 +207,7 @@ impl JsonValue {
|
|||
}
|
||||
i += 1;
|
||||
}
|
||||
if i == blob.len() {
|
||||
if i >= blob.len() {
|
||||
bail!("Unterminated string at {i}");
|
||||
}
|
||||
assert_eq!(blob[i], b'"');
|
||||
|
|
@ -874,4 +874,10 @@ mod test {
|
|||
]);
|
||||
assert_eq!(result, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn json_decode_unterminated_string_with_escape() {
|
||||
let input = b"\"\\";
|
||||
let _ = JsonValue::parse(input);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue