Check for unterminated strings properly

Also, public to enable fuzzing. This was the first catch!
This commit is contained in:
John Doty 2024-08-12 09:41:22 -07:00
parent 9b0a39fa90
commit 77cbf1700f
4 changed files with 11 additions and 5 deletions

View file

@ -1,7 +1,7 @@
mod client;
mod message;
mod reverse;
mod server;
pub mod server;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const REV: &str = env!("REPO_REV");

View file

@ -5,7 +5,7 @@ use log::{error, warn};
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, BufReader, BufWriter};
use tokio::sync::mpsc;
mod refresh;
pub mod refresh;
// We drive writes through an mpsc queue, because we not only handle requests
// and responses from the client (refresh ports and the like) but also need

View file

@ -10,7 +10,7 @@ use crate::message::PortDesc;
mod procfs;
#[cfg(unix)]
mod docker;
pub mod docker;
pub async fn get_entries(_send_anonymous: bool) -> Result<Vec<PortDesc>> {
#[cfg_attr(not(target_os = "linux"), allow(unused_mut))]

View file

@ -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);
}
}