Skip to content

Commit

Permalink
fix: invalid utf-8 in log crashes fblog
Browse files Browse the repository at this point in the history
People seem to write all kind of interessting stuff to log files. In my
case mod security and nginx...
  • Loading branch information
bomgar committed Oct 18, 2024
1 parent 3eea0bc commit 3e53e4a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions sample.invalid_string.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
çÚ„…(o²ÉÌy¿ÛÚ]å^}%ÛˆÞ`&Hc–´û²Q°
16 changes: 10 additions & 6 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ pub fn process_input(
handlebars: &Handlebars<'static>,
) {
for line in input.lines() {
let read_line = &line.expect("Should be able to read line");
match process_input_line(log_settings, read_line, None, maybe_filter, implicit_return, handlebars) {
Ok(_) => (),
Err(_) => print_unknown_line(read_line),
match line {
Ok(read_line) => match process_input_line(log_settings, &read_line, None, maybe_filter, implicit_return, handlebars) {
Ok(_) => (),
Err(_) => print_raw_line(&read_line, &ORANGE),
},
Err(e) => {
print_raw_line(&format!("Could not read line: {e}"), &Color::Red);
}
}
}
}

fn print_unknown_line(line: &str) {
let write_result = writeln!(&mut io::stdout(), "{} {}", "??? >".fg(*ORANGE).bold(), line);
fn print_raw_line(line: &str, c: &Color) {
let write_result = writeln!(&mut io::stdout(), "{} {}", "??? >".fg(*c).bold(), line);
if write_result.is_err() {
// Output end reached
std::process::exit(14);
Expand Down

0 comments on commit 3e53e4a

Please sign in to comment.