Skip to content

Commit 6c3de3e

Browse files
authored
baseNM: protect names against argv[0] (#11373)
1 parent 9beb038 commit 6c3de3e

7 files changed

Lines changed: 32 additions & 4 deletions

File tree

src/uu/base32/src/base32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
1616
}
1717

1818
pub fn uu_app() -> Command {
19-
base_common::base_app(translate!("base32-about"), translate!("base32-usage"))
19+
base_common::base_app(translate!("base32-about"), translate!("base32-usage")).name("base32")
2020
}

src/uu/base32/src/base_common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn parse_base_cmd_args(args: impl uucore::Args, command: Command) -> UResult
104104
}
105105

106106
pub fn base_app(about: String, usage: String) -> Command {
107-
let cmd = Command::new(uucore::util_name())
107+
let cmd = Command::new("")
108108
.version(uucore::crate_version!())
109109
.about(about)
110110
.override_usage(format_usage(&usage))

src/uu/base64/src/base64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
1616
}
1717

1818
pub fn uu_app() -> Command {
19-
base_common::base_app(translate!("base64-about"), translate!("base64-usage"))
19+
base_common::base_app(translate!("base64-about"), translate!("base64-usage")).name("base64")
2020
}

src/uu/basenc/src/basenc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ fn get_encodings() -> Vec<(&'static str, Format, String)> {
4545

4646
pub fn uu_app() -> Command {
4747
let encodings = get_encodings();
48-
let mut command = base_common::base_app(translate!("basenc-about"), translate!("basenc-usage"));
48+
let mut command = base_common::base_app(translate!("basenc-about"), translate!("basenc-usage"))
49+
.name("basenc");
4950

5051
for encoding in &encodings {
5152
let raw_arg = Arg::new(encoding.0)

tests/by-util/test_base32.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66

77
use uutests::new_ucmd;
88

9+
#[test]
10+
fn test_version() {
11+
new_ucmd!()
12+
.arg("--version")
13+
.succeeds()
14+
.no_stderr()
15+
.stdout_is(format!("base32 {}\n", uucore::crate_version!()));
16+
}
17+
918
#[test]
1019
fn test_encode() {
1120
let input = "Hello, World!";

tests/by-util/test_base64.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
use uutests::at_and_ucmd;
1010
use uutests::new_ucmd;
1111

12+
#[test]
13+
fn test_version() {
14+
new_ucmd!()
15+
.arg("--version")
16+
.succeeds()
17+
.no_stderr()
18+
.stdout_is(format!("base64 {}\n", uucore::crate_version!()));
19+
}
20+
1221
#[test]
1322
#[cfg(target_os = "linux")]
1423
fn test_base64_non_utf8_paths() {

tests/by-util/test_basenc.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88

99
use uutests::{at_and_ucmd, new_ucmd};
1010

11+
#[test]
12+
fn test_version() {
13+
new_ucmd!()
14+
.arg("--version")
15+
.succeeds()
16+
.no_stderr()
17+
.stdout_is(format!("basenc {}\n", uucore::crate_version!()));
18+
}
19+
1120
#[test]
1221
fn test_z85_not_padded_decode() {
1322
// The z85 crate deviates from the standard in some cases; we have to catch those

0 commit comments

Comments
 (0)