Skip to content

Commit

Permalink
Check for unterminated strings properly
Browse files Browse the repository at this point in the history
Also, public to enable fuzzing. This was the first catch!
  • Loading branch information
DeCarabas committed Aug 12, 2024
1 parent 9b0a39f commit 77cbf17
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/server/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
10 changes: 8 additions & 2 deletions src/server/refresh/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async fn list_containers() -> Result<Vec<u8>> {
}

#[derive(Debug, PartialEq)]
enum JsonValue {
pub enum JsonValue {
Null,
True,
False,
Expand Down Expand Up @@ -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'"');
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 77cbf17

Please sign in to comment.