mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-16 23:42:27 +00:00
Enforce control line limit before trimming
This commit is contained in:
1 parent
cbc8279a80
commit
72da2d5d05
1 file changed
+3
-3
@@ -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