Enforce control line limit before trimming

This commit is contained in:
Dylan M. Taylor committed 2026-11-15 17:01:28 +00:00
1 parent cbc8279a80
commit 72da2d5d05
1 file changed
+3 -3
+3 -3
View File
@@ -7,13 +7,13 @@ use std::fmt::Display;
/// Process one bounded control line. Blank lines yield no response. Missing `params` becomes null;
/// arbitrary JSON ids are echoed and malformed JSON has a null id, matching the legacy protocol.
pub fn process_line<E: Display>(line: &str, max_bytes: usize, dispatch: impl FnOnce(&str, &Value) -> Result<Value, E>) -> Option<String> {
if line.len() > max_bytes {
return Some(error(None, "request exceeds byte limit"));
}
let trimmed = line.trim();
if trimmed.is_empty() {
return None;
}
if line.len() > max_bytes {
return Some(error(None, "request exceeds byte limit"));
}
let value: Value = match serde_json::from_str(trimmed) {
Ok(v) => v,
Err(e) => return Some(error(None, &format!("bad request envelope: {e}"))),