Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure termination of syslog writer #857

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/log/syslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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..];

Expand Down
1 change: 1 addition & 0 deletions test-framework/e2e-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![cfg(test)]

mod pty;
mod regression;
mod su;

type Error = Box<dyn std::error::Error>;
Expand Down
17 changes: 17 additions & 0 deletions test-framework/e2e-tests/src/regression.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
Loading