mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 00:34:25 +00:00
Enforce control line limit before trimming
This commit is contained in:
@@ -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}"))),
|
||||
|
||||
Reference in New Issue
Block a user