-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure termination of syslog writer (#857)
Closing #856 This particular code has been struck by lightning a couple of times now and is pretty hard to reason about using formal reasoning (e.g. a loop invariant like `self.cursor < LIMIT` would seen to have to hold, but it doesn't really). This PR doesn't improve that situation (i.e. the formal reasoning), but it does ensure termination. As a minor side-fix, the code could also panic on line 54 if we hit the middle of a UTF8 character in exactly the wrong position, that is fixed as well. I'll work on an implementation of this writer in a more declarative style.
- Loading branch information
Showing
3 changed files
with
25 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |