From 528499fa888bf7cba113ad32b6c3ddd9643e58a4 Mon Sep 17 00:00:00 2001 From: Marc Schoolderman Date: Fri, 23 Aug 2024 16:11:54 +0200 Subject: [PATCH 1/2] patch: ensure termination of syslog writer --- src/log/syslog.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/log/syslog.rs b/src/log/syslog.rs index 86eff0554..10df1fcd9 100644 --- a/src/log/syslog.rs +++ b/src/log/syslog.rs @@ -51,14 +51,20 @@ impl Write for SysLogWriter { if self.cursor + message.len() > LIMIT { // floor_char_boundary is currently unstable let mut truncate_boundary = LIMIT - self.cursor; - while !message.is_char_boundary(truncate_boundary) { + while truncate_boundary > 0 && !message.is_char_boundary(truncate_boundary) { truncate_boundary -= 1; } + // don't overzealously truncate log messages truncate_boundary = message[..truncate_boundary] .rfind(|c: char| c.is_ascii_whitespace()) .unwrap_or(truncate_boundary); + if truncate_boundary == 0 { + // we failed to find a "nice" cut off point, abruptly cut off the msg + truncate_boundary = LIMIT - self.cursor; + } + let left = &message[..truncate_boundary]; let right = &message[truncate_boundary..]; From 6b5151d75d37c0184300bf4f3332f474c8540a40 Mon Sep 17 00:00:00 2001 From: Marc Schoolderman Date: Fri, 23 Aug 2024 16:33:25 +0200 Subject: [PATCH 2/2] add regression test --- test-framework/e2e-tests/src/lib.rs | 1 + test-framework/e2e-tests/src/regression.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 test-framework/e2e-tests/src/regression.rs diff --git a/test-framework/e2e-tests/src/lib.rs b/test-framework/e2e-tests/src/lib.rs index a9f98cbdf..3d9008f26 100644 --- a/test-framework/e2e-tests/src/lib.rs +++ b/test-framework/e2e-tests/src/lib.rs @@ -1,6 +1,7 @@ #![cfg(test)] mod pty; +mod regression; mod su; type Error = Box; diff --git a/test-framework/e2e-tests/src/regression.rs b/test-framework/e2e-tests/src/regression.rs new file mode 100644 index 000000000..967aaf75a --- /dev/null +++ b/test-framework/e2e-tests/src/regression.rs @@ -0,0 +1,17 @@ +use sudo_test::{Command, Env, TextFile}; + +use crate::Result; + +#[test] +fn syslog_writer_should_not_hang() -> Result<()> { + let env = Env(TextFile("ALL ALL=(ALL:ALL) NOPASSWD: ALL").chmod("644")).build()?; + + let stdout = Command::new("sudo") + .args(["env", "CC=clang-18", "CXX=clang++-18", "FOO=\"........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................\"", "whoami"]) + .output(&env)? + .stdout()?; + + assert_eq!(stdout, "root"); + + Ok(()) +}