From fcff6fec6d2e14940f54a8d7c7a51c88cb25dbe9 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 16 Jan 2022 23:33:09 +0100 Subject: [PATCH 1/5] Force minimal version of chrono to avoid a security issue See: https://rustsec.org/advisories/RUSTSEC-2020-0071.html --- Cargo.toml | 2 +- src/uu/date/Cargo.toml | 2 +- src/uu/du/Cargo.toml | 2 +- src/uu/uptime/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e72551516..dca5edf85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -362,7 +362,7 @@ yes = { optional=true, version="0.0.9", package="uu_yes", path="src/uu/yes" #pin_cc = { version="1.0.61, < 1.0.62", package="cc" } ## cc v1.0.62 has compiler errors for MinRustV v1.32.0, requires 1.34 (for `std::str::split_ascii_whitespace()`) [dev-dependencies] -chrono = "0.4.11" +chrono = "^0.4.11" conv = "0.3" filetime = "0.2" glob = "0.3.0" diff --git a/src/uu/date/Cargo.toml b/src/uu/date/Cargo.toml index f08c9668d..7e7d033f5 100644 --- a/src/uu/date/Cargo.toml +++ b/src/uu/date/Cargo.toml @@ -15,7 +15,7 @@ edition = "2018" path = "src/date.rs" [dependencies] -chrono = "0.4.4" +chrono = "^0.4.11" clap = { version = "2.33", features = ["wrap_help"] } uucore = { version=">=0.0.11", package="uucore", path="../../uucore" } uucore_procs = { version=">=0.0.8", package="uucore_procs", path="../../uucore_procs" } diff --git a/src/uu/du/Cargo.toml b/src/uu/du/Cargo.toml index 4018e7aef..b4bbdab1d 100644 --- a/src/uu/du/Cargo.toml +++ b/src/uu/du/Cargo.toml @@ -16,7 +16,7 @@ path = "src/du.rs" [dependencies] clap = { version = "2.33", features = ["wrap_help"] } -chrono = "0.4" +chrono = "^0.4.11" uucore = { version=">=0.0.11", package="uucore", path="../../uucore" } uucore_procs = { version=">=0.0.8", package="uucore_procs", path="../../uucore_procs" } diff --git a/src/uu/uptime/Cargo.toml b/src/uu/uptime/Cargo.toml index d6ddc8e34..f19f5fe59 100644 --- a/src/uu/uptime/Cargo.toml +++ b/src/uu/uptime/Cargo.toml @@ -15,7 +15,7 @@ edition = "2018" path = "src/uptime.rs" [dependencies] -chrono = "0.4" +chrono = "^0.4.11" clap = { version = "2.33", features = ["wrap_help"] } uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["libc", "utmpx"] } uucore_procs = { version=">=0.0.8", package="uucore_procs", path="../../uucore_procs" } From 346415e1d2a2ff5b2a1859b7ad0473d1b34c5790 Mon Sep 17 00:00:00 2001 From: Justin Tracey Date: Wed, 5 Jan 2022 23:26:12 -0500 Subject: [PATCH 2/5] join: add support for -z option --- src/uu/join/src/join.rs | 42 +++++++++++++++++++++++++++++---- tests/by-util/test_join.rs | 10 ++++++++ tests/fixtures/join/z.expected | Bin 0 -> 12 bytes 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/join/z.expected diff --git a/src/uu/join/src/join.rs b/src/uu/join/src/join.rs index 0c881f20d..a338a22c4 100644 --- a/src/uu/join/src/join.rs +++ b/src/uu/join/src/join.rs @@ -25,6 +25,13 @@ enum FileNum { File2, } +#[repr(u8)] +#[derive(Copy, Clone)] +enum LineEnding { + Nul = 0, + Newline = b'\n', +} + #[derive(Copy, Clone)] enum Sep { Char(u8), @@ -46,6 +53,7 @@ struct Settings { print_unpaired2: bool, print_joined: bool, ignore_case: bool, + line_ending: LineEnding, separator: Sep, autoformat: bool, format: Vec, @@ -63,6 +71,7 @@ impl Default for Settings { print_unpaired2: false, print_joined: true, ignore_case: false, + line_ending: LineEnding::Newline, separator: Sep::Whitespaces, autoformat: false, format: vec![], @@ -75,14 +84,21 @@ impl Default for Settings { /// Output representation. struct Repr<'a> { + line_ending: LineEnding, separator: u8, format: &'a [Spec], empty: &'a [u8], } impl<'a> Repr<'a> { - fn new(separator: u8, format: &'a [Spec], empty: &'a [u8]) -> Repr<'a> { + fn new( + line_ending: LineEnding, + separator: u8, + format: &'a [Spec], + empty: &'a [u8], + ) -> Repr<'a> { Repr { + line_ending, separator, format, empty, @@ -133,6 +149,10 @@ impl<'a> Repr<'a> { } Ok(()) } + + fn print_line_ending(&self) -> Result<(), std::io::Error> { + stdout().write_all(&[self.line_ending as u8]) + } } /// Input processing parameters. @@ -260,6 +280,7 @@ impl<'a> State<'a> { name: &'a str, stdin: &'a Stdin, key: usize, + line_ending: LineEnding, print_unpaired: bool, ) -> State<'a> { let f = if name == "-" { @@ -276,7 +297,7 @@ impl<'a> State<'a> { file_name: name, file_num, print_unpaired, - lines: f.split(b'\n'), + lines: f.split(line_ending as u8), seq: Vec::new(), line_num: 0, has_failed: false, @@ -351,7 +372,7 @@ impl<'a> State<'a> { repr.print_fields(line2, other.key)?; } - stdout().write_all(&[b'\n'])?; + repr.print_line_ending()?; } } @@ -461,7 +482,7 @@ impl<'a> State<'a> { repr.print_fields(line, self.key)?; } - stdout().write_all(&[b'\n']) + repr.print_line_ending() } fn print_first_line(&self, repr: &Repr) -> Result<(), std::io::Error> { @@ -540,6 +561,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { settings.headers = true; } + if matches.is_present("z") { + settings.line_ending = LineEnding::Nul; + } + let file1 = matches.value_of("file1").unwrap(); let file2 = matches.value_of("file2").unwrap(); @@ -646,6 +671,12 @@ FILENUM is 1 or 2, corresponding to FILE1 or FILE2", "treat the first line in each file as field headers, \ print them without trying to pair them", )) + .arg( + Arg::with_name("z") + .short("z") + .long("zero-terminated") + .help("line delimiter is NUL, not newline"), + ) .arg( Arg::with_name("file1") .required(true) @@ -668,6 +699,7 @@ fn exec(file1: &str, file2: &str, settings: Settings) -> Result<(), std::io::Err file1, &stdin, settings.key1, + settings.line_ending, settings.print_unpaired1, ); @@ -676,6 +708,7 @@ fn exec(file1: &str, file2: &str, settings: Settings) -> Result<(), std::io::Err file2, &stdin, settings.key2, + settings.line_ending, settings.print_unpaired2, ); @@ -705,6 +738,7 @@ fn exec(file1: &str, file2: &str, settings: Settings) -> Result<(), std::io::Err }; let repr = Repr::new( + settings.line_ending, match settings.separator { Sep::Char(sep) => sep, _ => b' ', diff --git a/tests/by-util/test_join.rs b/tests/by-util/test_join.rs index be25b9390..4b2d1bbba 100644 --- a/tests/by-util/test_join.rs +++ b/tests/by-util/test_join.rs @@ -346,3 +346,13 @@ fn non_unicode() { .succeeds() .stdout_only_fixture("non-unicode.expected"); } + +#[test] +fn null_line_endings() { + new_ucmd!() + .arg("-z") + .arg("non-unicode_1.bin") + .arg("non-unicode_2.bin") + .succeeds() + .stdout_only_fixture("z.expected"); +} diff --git a/tests/fixtures/join/z.expected b/tests/fixtures/join/z.expected new file mode 100644 index 0000000000000000000000000000000000000000..ed85bb05393f487f3b5e9f736d0611d140a046f3 GIT binary patch literal 12 TcmYdPSgx>~Aw?loA&mh57>)y9 literal 0 HcmV?d00001 From 9c14b943a8eeddb09ff25aab79db7dbb2b785607 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 17 Jan 2022 08:53:20 +0100 Subject: [PATCH 3/5] update pretty_assertions to version 1 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 50a25214a..5323fe628 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1361,9 +1361,9 @@ checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] name = "pretty_assertions" -version = "0.7.2" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cab0e7c02cf376875e9335e0ba1da535775beb5450d21e1dffca068818ed98b" +checksum = "ec0cfe1b2403f172ba0f234e500906ee0a3e493fb81092dac23ebefe129301cc" dependencies = [ "ansi_term", "ctor", diff --git a/Cargo.toml b/Cargo.toml index e72551516..e838fba65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -367,7 +367,7 @@ conv = "0.3" filetime = "0.2" glob = "0.3.0" libc = "0.2" -pretty_assertions = "0.7.2" +pretty_assertions = "1" rand = "0.7" regex = "1.0" sha1 = { version="0.6", features=["std"] } From 3dfb9a23c0e9967439dce67112849ed2c30b9d63 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 17 Jan 2022 08:53:20 +0100 Subject: [PATCH 4/5] update pretty_assertions to version 1 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 50a25214a..5323fe628 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1361,9 +1361,9 @@ checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] name = "pretty_assertions" -version = "0.7.2" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cab0e7c02cf376875e9335e0ba1da535775beb5450d21e1dffca068818ed98b" +checksum = "ec0cfe1b2403f172ba0f234e500906ee0a3e493fb81092dac23ebefe129301cc" dependencies = [ "ansi_term", "ctor", diff --git a/Cargo.toml b/Cargo.toml index dca5edf85..ef981a802 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -367,7 +367,7 @@ conv = "0.3" filetime = "0.2" glob = "0.3.0" libc = "0.2" -pretty_assertions = "0.7.2" +pretty_assertions = "1" rand = "0.7" regex = "1.0" sha1 = { version="0.6", features=["std"] } From eec2d79bbd0b8b47516ed9ae461d7a9aa7b5c0f3 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Mon, 17 Jan 2022 12:56:07 +0100 Subject: [PATCH 5/5] stbuf: remove the old comment --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ef981a802..07da3b2b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -328,7 +328,6 @@ sleep = { optional=true, version="0.0.9", package="uu_sleep", path="src/uu/sl sort = { optional=true, version="0.0.9", package="uu_sort", path="src/uu/sort" } split = { optional=true, version="0.0.9", package="uu_split", path="src/uu/split" } stat = { optional=true, version="0.0.9", package="uu_stat", path="src/uu/stat" } -# Very ugly, uncomment when the issue #2876 is fixed stdbuf = { optional=true, version="0.0.9", package="uu_stdbuf", path="src/uu/stdbuf" } sum = { optional=true, version="0.0.9", package="uu_sum", path="src/uu/sum" } sync = { optional=true, version="0.0.9", package="uu_sync", path="src/uu/sync" }