Reject null bytes and newlines in a user-supplied value.
(value: &str, field_name: &str)
| 70 | |
| 71 | /// Reject null bytes and newlines in a user-supplied value. |
| 72 | pub(super) fn reject_control_chars(value: &str, field_name: &str) -> Result<(), Status> { |
| 73 | if value.bytes().any(|b| b == 0) { |
| 74 | return Err(Status::invalid_argument(format!( |
| 75 | "{field_name} contains null bytes" |
| 76 | ))); |
| 77 | } |
| 78 | if value.bytes().any(|b| b == b'\n' || b == b'\r') { |
| 79 | return Err(Status::invalid_argument(format!( |
| 80 | "{field_name} contains newline or carriage return characters" |
| 81 | ))); |
| 82 | } |
| 83 | Ok(()) |
| 84 | } |
| 85 | |
| 86 | // --------------------------------------------------------------------------- |
| 87 | // Sandbox spec validation |
no outgoing calls
no test coverage detected